Skip to content

Commit 3a5bdef

Browse files
committed
whisper: deflake Test*MessageExpiration
These tests have become a common annoyance on CI. Fix them by allowing messages with expiration == now into the cache and delaying the check for expired message handling slightly.
1 parent fdc5a7d commit 3a5bdef

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

whisper/whisper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (self *Whisper) add(envelope *Envelope) error {
255255
defer self.poolMu.Unlock()
256256

257257
// short circuit when a received envelope has already expired
258-
if envelope.Expiry <= uint32(time.Now().Unix()) {
258+
if envelope.Expiry < uint32(time.Now().Unix()) {
259259
return nil
260260
}
261261

@@ -278,7 +278,6 @@ func (self *Whisper) add(envelope *Envelope) error {
278278
go self.postEvent(envelope)
279279
}
280280
glog.V(logger.Detail).Infof("cached whisper envelope %x\n", envelope)
281-
282281
return nil
283282
}
284283

whisper/whisper_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ func TestMessageExpiration(t *testing.T) {
179179
node := startTestCluster(1)[0]
180180

181181
message := NewMessage([]byte("expiring message"))
182-
envelope, err := message.Wrap(DefaultPoW, Options{
183-
TTL: time.Second,
184-
})
182+
envelope, err := message.Wrap(DefaultPoW, Options{TTL: time.Second})
185183
if err != nil {
186184
t.Fatalf("failed to wrap message: %v", err)
187185
}
@@ -197,23 +195,22 @@ func TestMessageExpiration(t *testing.T) {
197195
t.Fatalf("message not found in cache")
198196
}
199197
// Wait for expiration and check cache again
200-
time.Sleep(time.Second) // wait for expiration
201-
time.Sleep(expirationCycle) // wait for cleanup cycle
198+
time.Sleep(time.Second) // wait for expiration
199+
time.Sleep(2 * expirationCycle) // wait for cleanup cycle
202200

203201
node.poolMu.RLock()
204202
_, found = node.messages[envelope.Hash()]
205203
node.poolMu.RUnlock()
206-
207204
if found {
208205
t.Fatalf("message not expired from cache")
209206
}
210207

208+
// Check that adding an expired envelope doesn't do anything.
211209
node.add(envelope)
212210
node.poolMu.RLock()
213211
_, found = node.messages[envelope.Hash()]
214212
node.poolMu.RUnlock()
215213
if found {
216214
t.Fatalf("message was added to cache")
217215
}
218-
219216
}

0 commit comments

Comments
 (0)