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

Commit

Permalink
swarm/network/stream: fix TestGetSubscriptionsRPC data race
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Feb 8, 2019
1 parent edfee9c commit 91f8735
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions swarm/network/stream/streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,9 @@ func TestGetSubscriptionsRPC(t *testing.T) {
t.Fatal("Context timed out")
}

lock.RLock()
log.Debug("Expected message count: ", "expectedMsgCount", expectedMsgCount)
lock.RUnlock()
//now iterate again, this time we call each node via RPC to get its subscriptions
realCount := 0
for _, node := range nodes {
Expand Down Expand Up @@ -1324,8 +1326,11 @@ func TestGetSubscriptionsRPC(t *testing.T) {
}
}
// every node is mutually subscribed to each other, so the actual count is half of it
if realCount/2 != expectedMsgCount {
return fmt.Errorf("Real subscriptions and expected amount don't match; real: %d, expected: %d", realCount/2, expectedMsgCount)
lock.RLock()
emc := expectedMsgCount
lock.RUnlock()
if realCount/2 != emc {
return fmt.Errorf("Real subscriptions and expected amount don't match; real: %d, expected: %d", realCount/2, emc)
}
return nil
})
Expand Down

0 comments on commit 91f8735

Please sign in to comment.