Made TestSubscriptionNotification thread safe

This commit is contained in:
Adin Schmahmann 2019-06-07 09:21:17 -04:00
parent 8037a2e60f
commit cc791f28b9
1 changed files with 5 additions and 0 deletions

View File

@ -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")