From 76c6758b0089010c43b9a78bf9bbe985be6e2658 Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Mon, 10 Dec 2018 16:24:00 +0100 Subject: [PATCH] p2p/simulations: TestSnapshot wait for all connections before returning --- p2p/simulations/network_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/p2p/simulations/network_test.go b/p2p/simulations/network_test.go index 7476f17300..209960caa8 100644 --- a/p2p/simulations/network_test.go +++ b/p2p/simulations/network_test.go @@ -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 @@ -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 @@ -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()