swarm/network/stream: fix TestGetSubscriptionsRPC data race

https://github.com/ethersphere/go-ethereum/issues/1198#issuecomment-461768477
This commit is contained in:
Janos Guljas 2019-02-08 12:42:12 +01:00
parent edfee9cacb
commit 91f87355a2

View file

@ -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 {
@ -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
})