aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisper_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-15 15:50:31 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-15 15:50:31 +0800
commitbcf41797cacac35879d6bc153d3e4ce3cd9896f0 (patch)
treef3b377dac41c47e1f854fe3a8ffa4f16a577137e /whisper/whisper_test.go
parent4fb7ab5d090a49837ca50318fab468b056f2ec9f (diff)
downloadgo-tangerine-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.gz
go-tangerine-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.zst
go-tangerine-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.zip
whisper: global message expiration tests, polishes
Diffstat (limited to 'whisper/whisper_test.go')
-rw-r--r--whisper/whisper_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go
index df27a945e..c072ba26b 100644
--- a/whisper/whisper_test.go
+++ b/whisper/whisper_test.go
@@ -156,3 +156,29 @@ func testBroadcast(anonymous bool, t *testing.T) {
}
}
}
+
+func TestMessageExpiration(t *testing.T) {
+ // Start the single node cluster and inject a dummy message
+ node := startTestCluster(1)[0]
+
+ message := NewMessage([]byte("expiring message"))
+ envelope, err := message.Wrap(DefaultPoW, Options{
+ TTL: time.Second,
+ })
+ if err != nil {
+ t.Fatalf("failed to wrap message: %v", err)
+ }
+ if err := node.Send(envelope); err != nil {
+ t.Fatalf("failed to inject message: %v", err)
+ }
+ // Check that the message is inside the cache
+ if _, ok := node.messages[envelope.Hash()]; !ok {
+ t.Fatalf("message not found in cache")
+ }
+ // Wait for expiration and check cache again
+ time.Sleep(time.Second) // wait for expiration
+ time.Sleep(expirationTicks) // wait for cleanup cycle
+ if _, ok := node.messages[envelope.Hash()]; ok {
+ t.Fatalf("message not expired from cache")
+ }
+}