Skip to content

Commit 636f67f

Browse files
committed
Merge pull request #1969 from karalabe/fix-whisper-tests-datarace
whisper: fix datarace in expiration test
2 parents eb11c0e + 60e0abb commit 636f67f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

whisper/whisper_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,22 @@ func TestMessageExpiration(t *testing.T) {
189189
t.Fatalf("failed to inject message: %v", err)
190190
}
191191
// Check that the message is inside the cache
192-
if _, ok := node.messages[envelope.Hash()]; !ok {
192+
node.poolMu.RLock()
193+
_, found := node.messages[envelope.Hash()]
194+
node.poolMu.RUnlock()
195+
196+
if !found {
193197
t.Fatalf("message not found in cache")
194198
}
195199
// Wait for expiration and check cache again
196200
time.Sleep(time.Second) // wait for expiration
197201
time.Sleep(expirationCycle) // wait for cleanup cycle
198-
if _, ok := node.messages[envelope.Hash()]; ok {
202+
203+
node.poolMu.RLock()
204+
_, found = node.messages[envelope.Hash()]
205+
node.poolMu.RUnlock()
206+
207+
if found {
199208
t.Fatalf("message not expired from cache")
200209
}
201210
}

0 commit comments

Comments
 (0)