From cf49adf40052a88ea6a7ff314260af0326104ce2 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Tue, 27 Mar 2018 18:13:16 +0200 Subject: [PATCH 1/5] swarm/pss: enable pss tests --- swarm/network/kademlia.go | 7 +++---- swarm/pss/pss_test.go | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index e1888ca85c..d2200a6d42 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -17,7 +17,6 @@ package network import ( - "bytes" "fmt" "math/rand" "strings" @@ -183,9 +182,9 @@ func (k *Kademlia) Register(peers []OverlayAddr) error { for _, p := range peers { // error if self received, peer should know better // and should be punished for this - if bytes.Equal(p.Address(), k.base) { - return fmt.Errorf("add peers: %x is self", k.base) - } + //if bytes.Equal(p.Address(), k.base) { + //return fmt.Errorf("add peers: %x is self", k.base) + //} var found bool k.addrs, _, found, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val { // if not found diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index e26a7e600a..f689b683e5 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -635,7 +635,7 @@ func worker(id int, jobs <-chan Job, rpcs map[discover.NodeID]*rpc.Client, pubke // params in run name: // nodes/msgs/addrbytes/adaptertype // if adaptertype is exec uses execadapter, simadapter otherwise -func XTestNetwork(t *testing.T) { +func TestNetwork(t *testing.T) { t.Run("3/2000/4/sock", testNetwork) t.Run("4/2000/4/sock", testNetwork) t.Run("8/2000/4/sock", testNetwork) @@ -706,6 +706,8 @@ func testNetwork(t *testing.T) { t.Fatal(err) } + time.Sleep(1 * time.Second) + triggerChecks := func(trigger chan discover.NodeID, id discover.NodeID, rpcclient *rpc.Client, topic string) error { msgC := make(chan APIMsg) ctx, cancel := context.WithTimeout(context.Background(), time.Second) @@ -764,12 +766,16 @@ func testNetwork(t *testing.T) { } } + time.Sleep(1 * time.Second) + // setup workers jobs := make(chan Job, 10) for w := 1; w <= 10; w++ { go worker(w, jobs, rpcs, pubkeys, topic) } + time.Sleep(1 * time.Second) + for i := 0; i < int(msgcount); i++ { sendnodeidx := rand.Intn(int(nodecount)) recvnodeidx := rand.Intn(int(nodecount - 1)) From d1c46e3ddef27e5712cfaebf3f630fed43197376 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Tue, 27 Mar 2018 19:01:08 +0200 Subject: [PATCH 2/5] swarm: do not cache newService() --- swarm/network/kademlia.go | 7 ++++--- swarm/pss/pss_test.go | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index d2200a6d42..e1888ca85c 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -17,6 +17,7 @@ package network import ( + "bytes" "fmt" "math/rand" "strings" @@ -182,9 +183,9 @@ func (k *Kademlia) Register(peers []OverlayAddr) error { for _, p := range peers { // error if self received, peer should know better // and should be punished for this - //if bytes.Equal(p.Address(), k.base) { - //return fmt.Errorf("add peers: %x is self", k.base) - //} + if bytes.Equal(p.Address(), k.base) { + return fmt.Errorf("add peers: %x is self", k.base) + } var found bool k.addrs, _, found, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val { // if not found diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index f689b683e5..54b3c0988a 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -57,13 +57,11 @@ var ( useHandshake bool ) -var services = newServices() - func init() { flag.Parse() rand.Seed(time.Now().Unix()) - adapters.RegisterServices(services) + adapters.RegisterServices(newServices()) initTest() } @@ -677,11 +675,11 @@ func testNetwork(t *testing.T) { } a = adapters.NewExecAdapter(dirname) } else if adapter == "sock" { - a = adapters.NewSocketAdapter(services) + a = adapters.NewSocketAdapter(newServices()) } else if adapter == "tcp" { - a = adapters.NewTCPAdapter(services) + a = adapters.NewTCPAdapter(newServices()) } else if adapter == "sim" { - a = adapters.NewSimAdapter(services) + a = adapters.NewSimAdapter(newServices()) } net := simulations.NewNetwork(a, &simulations.NetworkConfig{ ID: "0", @@ -1082,7 +1080,7 @@ func setupNetwork(numnodes int) (clients []*rpc.Client, err error) { if numnodes < 2 { return nil, fmt.Errorf("Minimum two nodes in network") } - adapter := adapters.NewSimAdapter(services) + adapter := adapters.NewSimAdapter(newServices()) net := simulations.NewNetwork(adapter, &simulations.NetworkConfig{ ID: "0", DefaultService: "bzz", From 6417cc691e4d6958db4747beed13b04b674249eb Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Tue, 27 Mar 2018 23:46:19 +0200 Subject: [PATCH 3/5] swarm/pss: remove test with 64 nodes which fail on Travis --- swarm/pss/pss_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index 54b3c0988a..ee4cdb5248 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -638,8 +638,6 @@ func TestNetwork(t *testing.T) { t.Run("4/2000/4/sock", testNetwork) t.Run("8/2000/4/sock", testNetwork) t.Run("16/2000/4/sock", testNetwork) - t.Run("32/2000/4/sock", testNetwork) - t.Run("64/2000/4/sim", testNetwork) } func testNetwork(t *testing.T) { From e62cf05c9e9d0a2cf9c102e84541824e6bdf8355 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 30 Mar 2018 12:48:08 +0200 Subject: [PATCH 4/5] swarm/pss: disable tests on darwin --- swarm/pss/pss_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swarm/pss/pss_test.go b/swarm/pss/pss_test.go index ee4cdb5248..774dfa0f15 100644 --- a/swarm/pss/pss_test.go +++ b/swarm/pss/pss_test.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "math/rand" "os" + "runtime" "strconv" "strings" "sync" @@ -634,10 +635,21 @@ func worker(id int, jobs <-chan Job, rpcs map[discover.NodeID]*rpc.Client, pubke // nodes/msgs/addrbytes/adaptertype // if adaptertype is exec uses execadapter, simadapter otherwise func TestNetwork(t *testing.T) { + if runtime.GOOS == "darwin" { + t.Skip("Travis macOS build seems to be very slow, and these tests are flaky on it. Skipping until we find a solution.") + } + t.Run("3/2000/4/sock", testNetwork) t.Run("4/2000/4/sock", testNetwork) t.Run("8/2000/4/sock", testNetwork) t.Run("16/2000/4/sock", testNetwork) + t.Run("32/2000/4/sock", testNetwork) + + t.Run("3/2000/4/sim", testNetwork) + t.Run("4/2000/4/sim", testNetwork) + t.Run("8/2000/4/sim", testNetwork) + t.Run("16/2000/4/sim", testNetwork) + t.Run("32/2000/4/sim", testNetwork) } func testNetwork(t *testing.T) { From 218586aa91e9e6faaf5dc0c9ec56d561699ba780 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 30 Mar 2018 15:00:57 +0200 Subject: [PATCH 5/5] swarm/storage: remove unnecessary conversion --- swarm/storage/hasherstore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/storage/hasherstore.go b/swarm/storage/hasherstore.go index a247816b78..44999d3453 100644 --- a/swarm/storage/hasherstore.go +++ b/swarm/storage/hasherstore.go @@ -95,7 +95,7 @@ func (h *hasherStore) Put(chunkData ChunkData) (Reference, error) { // If the data is encrypted and the reference contains an encryption key, it will be decrypted before // return. func (h *hasherStore) Get(ref Reference) (ChunkData, error) { - key, encryptionKey, err := parseReference(ref, int(h.hashSize)) + key, encryptionKey, err := parseReference(ref, h.hashSize) if err != nil { return nil, err }