From 60e0abb5957560ba760ba4ed2669244f2528bd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 5 Nov 2015 13:36:25 +0200 Subject: [PATCH] whisper: fix datarace in expiration test --- whisper/whisper_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go index b5a919984..1a9a8667a 100644 --- a/whisper/whisper_test.go +++ b/whisper/whisper_test.go @@ -189,13 +189,22 @@ func TestMessageExpiration(t *testing.T) { t.Fatalf("failed to inject message: %v", err) } // Check that the message is inside the cache - if _, ok := node.messages[envelope.Hash()]; !ok { + node.poolMu.RLock() + _, found := node.messages[envelope.Hash()] + node.poolMu.RUnlock() + + if !found { t.Fatalf("message not found in cache") } // Wait for expiration and check cache again time.Sleep(time.Second) // wait for expiration time.Sleep(expirationCycle) // wait for cleanup cycle - if _, ok := node.messages[envelope.Hash()]; ok { + + node.poolMu.RLock() + _, found = node.messages[envelope.Hash()] + node.poolMu.RUnlock() + + if found { t.Fatalf("message not expired from cache") } }