github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/swarm/network/simulation/kademlia_test.go (about) 1 // Copyleft 2018 The susy-graviton Authors 2 // This file is part of the susy-graviton library. 3 // 4 // The susy-graviton library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The susy-graviton library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MSRCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the susy-graviton library. If not, see <http://www.gnu.org/licenses/>. 16 17 package simulation 18 19 import ( 20 "context" 21 "sync" 22 "testing" 23 "time" 24 25 "github.com/susy-go/susy-graviton/node" 26 "github.com/susy-go/susy-graviton/p2p/simulations/adapters" 27 "github.com/susy-go/susy-graviton/swarm/network" 28 ) 29 30 func TestWaitTillHealthy(t *testing.T) { 31 t.Skip("WaitTillHealthy depends on discovery, which relies on a reliable SuggestPeer, which is not reliable") 32 33 sim := New(map[string]ServiceFunc{ 34 "bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) { 35 addr := network.NewAddr(ctx.Config.Node()) 36 hp := network.NewHiveParams() 37 config := &network.BzzConfig{ 38 OverlayAddr: addr.Over(), 39 UnderlayAddr: addr.Under(), 40 HiveParams: hp, 41 } 42 kad := network.NewKademlia(addr.Over(), network.NewKadParams()) 43 // store kademlia in node's bucket under BucketKeyKademlia 44 // so that it can be found by WaitTillHealthy method. 45 b.Store(BucketKeyKademlia, kad) 46 return network.NewBzz(config, kad, nil, nil, nil), nil, nil 47 }, 48 }) 49 defer sim.Close() 50 51 _, err := sim.AddNodesAndConnectRing(10) 52 if err != nil { 53 t.Fatal(err) 54 } 55 56 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) 57 defer cancel() 58 ill, err := sim.WaitTillHealthy(ctx) 59 if err != nil { 60 for id, kad := range ill { 61 t.Log("Node", id) 62 t.Log(kad.String()) 63 } 64 if err != nil { 65 t.Fatal(err) 66 } 67 } 68 }