p2p/simulation: Revert to before wait for snap load (5e75594)

This commit is contained in:
lash 2018-12-12 14:54:10 +01:00
parent 76c6758b00
commit 834bafd010

View file

@ -175,25 +175,24 @@ OUTER:
// subscribe to peer events
// every node up and conn up event will generate one additional control event
// therefore multiply the count by two
evC = make(chan *Event)
evC = make(chan *Event, (len(snap.Conns)*2)+(len(snap.Nodes)*2))
sub = network.Events().Subscribe(evC)
defer sub.Unsubscribe()
// Channel that is signalling when the Load function returns
// to fail the test in the event for loop if that happens
// before all connection events are counted.
loadDoneC := make(chan struct{})
// Channel that signals when all connections are established.
connsC := make(chan struct{})
// load the snapshot
// spawn separate thread to avoid deadlock in the event listeners
err = network.Load(snap)
if err != nil {
t.Fatal(err)
}
go func() {
// collect connection events up to expected number
ctx, cancel = context.WithTimeout(context.TODO(), time.Second*3)
defer cancel()
connEventCount = nodeCount
OUTER_TWO:
OUTER_TWO:
for {
select {
case <-ctx.Done():
@ -214,10 +213,6 @@ OUTER:
break OUTER_TWO
}
}
case <-loadDoneC:
// if load function returns before all expected events are caught.
// fail the test
t.Fatal("load function returned before all connections are established")
}
}
@ -240,33 +235,13 @@ OUTER:
}
}
// close the channel to signal that all connections are established
close(connsC)
}()
// load the snapshot
// spawn separate thread to avoid deadlock in the event listeners
err = network.Load(snap)
if err != nil {
t.Fatal(err)
}
// signal the event for event loop that Load function has returned
close(loadDoneC)
// wait for all connections
select {
case <-connsC:
case <-time.After(10 * time.Second):
t.Fatal("timing out waiting for connections")
}
// verify that network didn't generate any other additional connection events after the ones we have collected within a reasonable period of time
ctx, cancel = context.WithTimeout(context.TODO(), time.Second)
defer cancel()
select {
case <-ctx.Done():
case ev := <-evC:
if ev.Type == EventTypeConn && !ev.Control {
if ev.Type == EventTypeConn {
t.Fatalf("Superfluous conn found %v -> %v", ev.Conn.One, ev.Conn.Other)
}
}