aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-04-15 19:44:36 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-04-15 19:44:36 +0800
commit5c17b2f5211ec98a87140c874483681de4e34391 (patch)
tree8bd84be7b7b0051d918ec229f8a3de6a0397dd2b
parentfdc5a7dc1a1764c63190a649f70296cbdbc0abe1 (diff)
parent3a5bdef962ece873791ab838480892fd75110af1 (diff)
downloadgo-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar.gz
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar.bz2
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar.lz
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar.xz
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.tar.zst
go-tangerine-5c17b2f5211ec98a87140c874483681de4e34391.zip
Merge pull request #2460 from fjl/whisper-expiration-test-delay
whisper: deflake Test*MessageExpiration
-rw-r--r--whisper/whisper.go3
-rw-r--r--whisper/whisper_test.go11
2 files changed, 5 insertions, 9 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go
index e5f686e43..0a49c1000 100644
--- a/whisper/whisper.go
+++ b/whisper/whisper.go
@@ -255,7 +255,7 @@ func (self *Whisper) add(envelope *Envelope) error {
defer self.poolMu.Unlock()
// short circuit when a received envelope has already expired
- if envelope.Expiry <= uint32(time.Now().Unix()) {
+ if envelope.Expiry < uint32(time.Now().Unix()) {
return nil
}
@@ -278,7 +278,6 @@ func (self *Whisper) add(envelope *Envelope) error {
go self.postEvent(envelope)
}
glog.V(logger.Detail).Infof("cached whisper envelope %x\n", envelope)
-
return nil
}
diff --git a/whisper/whisper_test.go b/whisper/whisper_test.go
index 9cc235e7a..094df373c 100644
--- a/whisper/whisper_test.go
+++ b/whisper/whisper_test.go
@@ -179,9 +179,7 @@ func TestMessageExpiration(t *testing.T) {
node := startTestCluster(1)[0]
message := NewMessage([]byte("expiring message"))
- envelope, err := message.Wrap(DefaultPoW, Options{
- TTL: time.Second,
- })
+ envelope, err := message.Wrap(DefaultPoW, Options{TTL: time.Second})
if err != nil {
t.Fatalf("failed to wrap message: %v", err)
}
@@ -197,17 +195,17 @@ func TestMessageExpiration(t *testing.T) {
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
+ time.Sleep(time.Second) // wait for expiration
+ time.Sleep(2 * expirationCycle) // wait for cleanup cycle
node.poolMu.RLock()
_, found = node.messages[envelope.Hash()]
node.poolMu.RUnlock()
-
if found {
t.Fatalf("message not expired from cache")
}
+ // Check that adding an expired envelope doesn't do anything.
node.add(envelope)
node.poolMu.RLock()
_, found = node.messages[envelope.Hash()]
@@ -215,5 +213,4 @@ func TestMessageExpiration(t *testing.T) {
if found {
t.Fatalf("message was added to cache")
}
-
}