Merge pull request #2460 from fjl/whisper-expiration-test-delay

whisper: deflake Test*MessageExpiration
pull/2461/head
Péter Szilágyi 9 years ago
commit 5c17b2f521
  1. 3
      whisper/whisper.go
  2. 9
      whisper/whisper_test.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
}

@ -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)
}
@ -198,16 +196,16 @@ func TestMessageExpiration(t *testing.T) {
}
// Wait for expiration and check cache again
time.Sleep(time.Second) // wait for expiration
time.Sleep(expirationCycle) // wait for cleanup cycle
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")
}
}

Loading…
Cancel
Save