swarm/network/simulation: defer sim.Clsoe()

This commit is contained in:
Fabio Barone 2019-02-24 21:04:14 -05:00
parent aa001605b9
commit 6ba8a5b65c

View file

@ -50,6 +50,7 @@ func TestWaitTillHealthy(t *testing.T) {
// create the first simulation // create the first simulation
sim := New(simServiceMap) sim := New(simServiceMap)
defer sim.Close()
// connect and... // connect and...
_, err := sim.AddNodesAndConnectRing(testNodesNum) _, err := sim.AddNodesAndConnectRing(testNodesNum)
@ -77,7 +78,6 @@ func TestWaitTillHealthy(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
sim.Close()
// create a control simulation // create a control simulation
controlSim := New(createSimServiceMap(false)) controlSim := New(createSimServiceMap(false))
@ -88,6 +88,10 @@ func TestWaitTillHealthy(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = controlSim.WaitTillHealthy(ctx)
if err != nil {
t.Fatal(err)
}
// for each node... // for each node...
nodeIDs := controlSim.UpNodeIDs() nodeIDs := controlSim.UpNodeIDs()
if len(nodeIDs) != testNodesNum { if len(nodeIDs) != testNodesNum {
@ -122,6 +126,7 @@ func TestWaitTillHealthy(t *testing.T) {
healthy := info.Healthy() healthy := info.Healthy()
log.Trace("Node is healthy", "node", node, "healthy", healthy) log.Trace("Node is healthy", "node", node, "healthy", healthy)
if !healthy { if !healthy {
log.Trace("Unhealthy kademlia", "kad", kad.String())
t.Fatalf("Expected node %v of control simulation to be healthy, but it is not", node) t.Fatalf("Expected node %v of control simulation to be healthy, but it is not", node)
} }
} }