cmd/swarm: speed up tests (#17878)
These minor changes already shaved off around 30s.
This commit is contained in:
parent
0fe9a372b3
commit
da290e9707
@ -54,9 +54,8 @@ var DefaultCurve = crypto.S256()
|
|||||||
// is then fetched through 2nd node. since the tested code is not key-aware - we can just
|
// is then fetched through 2nd node. since the tested code is not key-aware - we can just
|
||||||
// fetch from the 2nd node using HTTP BasicAuth
|
// fetch from the 2nd node using HTTP BasicAuth
|
||||||
func TestAccessPassword(t *testing.T) {
|
func TestAccessPassword(t *testing.T) {
|
||||||
cluster := newTestCluster(t, 1)
|
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
|
||||||
defer cluster.Shutdown()
|
defer srv.Close()
|
||||||
proxyNode := cluster.Nodes[0]
|
|
||||||
|
|
||||||
dataFilename := testutil.TempFileWithContent(t, data)
|
dataFilename := testutil.TempFileWithContent(t, data)
|
||||||
defer os.RemoveAll(dataFilename)
|
defer os.RemoveAll(dataFilename)
|
||||||
@ -64,7 +63,7 @@ func TestAccessPassword(t *testing.T) {
|
|||||||
// upload the file with 'swarm up' and expect a hash
|
// upload the file with 'swarm up' and expect a hash
|
||||||
up := runSwarm(t,
|
up := runSwarm(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
proxyNode.URL, //it doesn't matter through which node we upload content
|
srv.URL, //it doesn't matter through which node we upload content
|
||||||
"up",
|
"up",
|
||||||
"--encrypt",
|
"--encrypt",
|
||||||
dataFilename)
|
dataFilename)
|
||||||
@ -138,7 +137,7 @@ func TestAccessPassword(t *testing.T) {
|
|||||||
if a.Publisher != "" {
|
if a.Publisher != "" {
|
||||||
t.Fatal("should be empty")
|
t.Fatal("should be empty")
|
||||||
}
|
}
|
||||||
client := swarm.NewClient(cluster.Nodes[0].URL)
|
client := swarm.NewClient(srv.URL)
|
||||||
|
|
||||||
hash, err := client.UploadManifest(&m, false)
|
hash, err := client.UploadManifest(&m, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,7 +146,7 @@ func TestAccessPassword(t *testing.T) {
|
|||||||
|
|
||||||
httpClient := &http.Client{}
|
httpClient := &http.Client{}
|
||||||
|
|
||||||
url := cluster.Nodes[0].URL + "/" + "bzz:/" + hash
|
url := srv.URL + "/" + "bzz:/" + hash
|
||||||
response, err := httpClient.Get(url)
|
response, err := httpClient.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -189,7 +188,7 @@ func TestAccessPassword(t *testing.T) {
|
|||||||
//download file with 'swarm down' with wrong password
|
//download file with 'swarm down' with wrong password
|
||||||
up = runSwarm(t,
|
up = runSwarm(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
proxyNode.URL,
|
srv.URL,
|
||||||
"down",
|
"down",
|
||||||
"bzz:/"+hash,
|
"bzz:/"+hash,
|
||||||
tmp,
|
tmp,
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/api"
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
|
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestManifestChange tests manifest add, update and remove
|
// TestManifestChange tests manifest add, update and remove
|
||||||
@ -57,8 +58,8 @@ func TestManifestChangeEncrypted(t *testing.T) {
|
|||||||
// Argument encrypt controls whether to use encryption or not.
|
// Argument encrypt controls whether to use encryption or not.
|
||||||
func testManifestChange(t *testing.T, encrypt bool) {
|
func testManifestChange(t *testing.T, encrypt bool) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
cluster := newTestCluster(t, 1)
|
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
|
||||||
defer cluster.Shutdown()
|
defer srv.Close()
|
||||||
|
|
||||||
tmp, err := ioutil.TempDir("", "swarm-manifest-test")
|
tmp, err := ioutil.TempDir("", "swarm-manifest-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,7 +95,7 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"--recursive",
|
"--recursive",
|
||||||
"--defaultpath",
|
"--defaultpath",
|
||||||
indexDataFilename,
|
indexDataFilename,
|
||||||
@ -109,7 +110,7 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
checkHashLength(t, origManifestHash, encrypt)
|
checkHashLength(t, origManifestHash, encrypt)
|
||||||
|
|
||||||
client := swarm.NewClient(cluster.Nodes[0].URL)
|
client := swarm.NewClient(srv.URL)
|
||||||
|
|
||||||
// upload a new file and use its manifest to add it the original manifest.
|
// upload a new file and use its manifest to add it the original manifest.
|
||||||
t.Run("add", func(t *testing.T) {
|
t.Run("add", func(t *testing.T) {
|
||||||
@ -122,14 +123,14 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
humansManifestHash := runSwarmExpectHash(t,
|
humansManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"up",
|
"up",
|
||||||
humansDataFilename,
|
humansDataFilename,
|
||||||
)
|
)
|
||||||
|
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"add",
|
"add",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -177,14 +178,14 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
robotsManifestHash := runSwarmExpectHash(t,
|
robotsManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"up",
|
"up",
|
||||||
robotsDataFilename,
|
robotsDataFilename,
|
||||||
)
|
)
|
||||||
|
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"add",
|
"add",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -237,14 +238,14 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
indexManifestHash := runSwarmExpectHash(t,
|
indexManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"up",
|
"up",
|
||||||
indexDataFilename,
|
indexDataFilename,
|
||||||
)
|
)
|
||||||
|
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"update",
|
"update",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -295,14 +296,14 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
humansManifestHash := runSwarmExpectHash(t,
|
humansManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"up",
|
"up",
|
||||||
robotsDataFilename,
|
robotsDataFilename,
|
||||||
)
|
)
|
||||||
|
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"update",
|
"update",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -348,7 +349,7 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
t.Run("remove", func(t *testing.T) {
|
t.Run("remove", func(t *testing.T) {
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"remove",
|
"remove",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -376,7 +377,7 @@ func testManifestChange(t *testing.T, encrypt bool) {
|
|||||||
t.Run("remove nested", func(t *testing.T) {
|
t.Run("remove nested", func(t *testing.T) {
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"remove",
|
"remove",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
@ -429,8 +430,8 @@ func TestNestedDefaultEntryUpdateEncrypted(t *testing.T) {
|
|||||||
|
|
||||||
func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
|
func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
cluster := newTestCluster(t, 1)
|
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
|
||||||
defer cluster.Shutdown()
|
defer srv.Close()
|
||||||
|
|
||||||
tmp, err := ioutil.TempDir("", "swarm-manifest-test")
|
tmp, err := ioutil.TempDir("", "swarm-manifest-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -458,7 +459,7 @@ func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"--recursive",
|
"--recursive",
|
||||||
"--defaultpath",
|
"--defaultpath",
|
||||||
indexDataFilename,
|
indexDataFilename,
|
||||||
@ -473,7 +474,7 @@ func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
checkHashLength(t, origManifestHash, encrypt)
|
checkHashLength(t, origManifestHash, encrypt)
|
||||||
|
|
||||||
client := swarm.NewClient(cluster.Nodes[0].URL)
|
client := swarm.NewClient(srv.URL)
|
||||||
|
|
||||||
newIndexData := []byte("<h1>Ethereum Swarm</h1>")
|
newIndexData := []byte("<h1>Ethereum Swarm</h1>")
|
||||||
newIndexDataFilename := filepath.Join(tmp, "index.html")
|
newIndexDataFilename := filepath.Join(tmp, "index.html")
|
||||||
@ -484,14 +485,14 @@ func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
|
|||||||
|
|
||||||
newIndexManifestHash := runSwarmExpectHash(t,
|
newIndexManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"up",
|
"up",
|
||||||
newIndexDataFilename,
|
newIndexDataFilename,
|
||||||
)
|
)
|
||||||
|
|
||||||
newManifestHash := runSwarmExpectHash(t,
|
newManifestHash := runSwarmExpectHash(t,
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"manifest",
|
"manifest",
|
||||||
"update",
|
"update",
|
||||||
origManifestHash,
|
origManifestHash,
|
||||||
|
@ -40,6 +40,9 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/swarm"
|
"github.com/ethereum/go-ethereum/swarm"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
|
swarmhttp "github.com/ethereum/go-ethereum/swarm/api/http"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
var loglevel = flag.Int("loglevel", 3, "verbosity of logs")
|
||||||
@ -55,6 +58,9 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serverFunc(api *api.API) testutil.TestServer {
|
||||||
|
return swarmhttp.NewServer(api, "")
|
||||||
|
}
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// check if we have been reexec'd
|
// check if we have been reexec'd
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
|
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/testutil"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -298,8 +299,8 @@ func TestCLISwarmUpDefaultPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T) {
|
func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T) {
|
||||||
cluster := newTestCluster(t, 1)
|
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
|
||||||
defer cluster.Shutdown()
|
defer srv.Close()
|
||||||
|
|
||||||
tmp, err := ioutil.TempDir("", "swarm-defaultpath-test")
|
tmp, err := ioutil.TempDir("", "swarm-defaultpath-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -323,7 +324,7 @@ func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T
|
|||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--bzzapi",
|
"--bzzapi",
|
||||||
cluster.Nodes[0].URL,
|
srv.URL,
|
||||||
"--recursive",
|
"--recursive",
|
||||||
"--defaultpath",
|
"--defaultpath",
|
||||||
defaultPath,
|
defaultPath,
|
||||||
@ -340,7 +341,7 @@ func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T
|
|||||||
up.ExpectExit()
|
up.ExpectExit()
|
||||||
hash := matches[0]
|
hash := matches[0]
|
||||||
|
|
||||||
client := swarm.NewClient(cluster.Nodes[0].URL)
|
client := swarm.NewClient(srv.URL)
|
||||||
|
|
||||||
m, isEncrypted, err := client.DownloadManifest(hash)
|
m, isEncrypted, err := client.DownloadManifest(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user