github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/swarm/network/simulation/kademlia_test.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-dubxcoin library. 3 // 4 // The go-dubxcoin 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 go-dubxcoin library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY 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 go-dubxcoin 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/alexdevranger/node-1.8.27/node" 26 "github.com/alexdevranger/node-1.8.27/p2p/simulations/adapters" 27 "github.com/alexdevranger/node-1.8.27/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 }