Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
p2p/simulations: TestSnapshot wait for all connections before returning
Browse files Browse the repository at this point in the history
  • Loading branch information
janos authored and nolash committed Dec 11, 2018
1 parent 4a218f4 commit 6fb6980
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions p2p/simulations/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ OUTER:
// 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{})

go func() {
// collect connection events up to expected number
Expand Down Expand Up @@ -237,6 +239,9 @@ OUTER:
t.Fatalf("network missing conn %v -> %v", snapConn.One, snapConn.Other)
}
}

// close the channel to signal that all connections are established
close(connsC)
}()

// load the snapshot
Expand All @@ -248,6 +253,13 @@ OUTER:
// 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()
Expand Down

0 comments on commit 6fb6980

Please sign in to comment.