Commit cc791f28 authored by Adin Schmahmann's avatar Adin Schmahmann

Made TestSubscriptionNotification thread safe

parent 8037a2e6
......@@ -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")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment