From 91f87355a2af8b96ce2304e4770e5be27b560a47 Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Fri, 8 Feb 2019 12:42:12 +0100 Subject: [PATCH] swarm/network/stream: fix TestGetSubscriptionsRPC data race https://github.com/ethersphere/go-ethereum/issues/1198#issuecomment-461768477 --- swarm/network/stream/streamer_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/swarm/network/stream/streamer_test.go b/swarm/network/stream/streamer_test.go index 27efdefab3..d0a552414b 100644 --- a/swarm/network/stream/streamer_test.go +++ b/swarm/network/stream/streamer_test.go @@ -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 })