From cc791f28b9886c28fe5235220468cafafaab1a48 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Fri, 7 Jun 2019 09:21:17 -0400 Subject: [PATCH] Made TestSubscriptionNotification thread safe --- floodsub_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/floodsub_test.go b/floodsub_test.go index c15c57d..47df0f5 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -1075,6 +1075,8 @@ func TestSubscriptionNotification(t *testing.T) { msgs := make([]*Subscription, numHosts) subPeersFound := make([]map[peer.ID]struct{}, numHosts) + + wg := sync.WaitGroup{} for i, ps := range psubs { subch, err := ps.Subscribe("foobar") if err != nil { @@ -1084,7 +1086,9 @@ func TestSubscriptionNotification(t *testing.T) { msgs[i] = subch peersFound := make(map[peer.ID]struct{}) subPeersFound[i] = peersFound + wg.Add(1) go func(peersFound map[peer.ID]struct{}) { + defer wg.Done() for i := 0; i < numHosts-1; i++ { pid, err := subch.NextSubscribedPeer(ctx) if err != nil { @@ -1099,6 +1103,7 @@ func TestSubscriptionNotification(t *testing.T) { time.Sleep(time.Millisecond * 100) + wg.Wait() for _, peersFound := range subPeersFound { if len(peersFound) != numHosts-1 { t.Fatal("incorrect number of peers found")