File tree Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -255,7 +255,7 @@ func (self *Whisper) add(envelope *Envelope) error {
255
255
defer self .poolMu .Unlock ()
256
256
257
257
// 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 ()) {
259
259
return nil
260
260
}
261
261
@@ -278,7 +278,6 @@ func (self *Whisper) add(envelope *Envelope) error {
278
278
go self .postEvent (envelope )
279
279
}
280
280
glog .V (logger .Detail ).Infof ("cached whisper envelope %x\n " , envelope )
281
-
282
281
return nil
283
282
}
284
283
Original file line number Diff line number Diff line change @@ -179,9 +179,7 @@ func TestMessageExpiration(t *testing.T) {
179
179
node := startTestCluster (1 )[0 ]
180
180
181
181
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 })
185
183
if err != nil {
186
184
t .Fatalf ("failed to wrap message: %v" , err )
187
185
}
@@ -197,23 +195,22 @@ func TestMessageExpiration(t *testing.T) {
197
195
t .Fatalf ("message not found in cache" )
198
196
}
199
197
// 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
202
200
203
201
node .poolMu .RLock ()
204
202
_ , found = node .messages [envelope .Hash ()]
205
203
node .poolMu .RUnlock ()
206
-
207
204
if found {
208
205
t .Fatalf ("message not expired from cache" )
209
206
}
210
207
208
+ // Check that adding an expired envelope doesn't do anything.
211
209
node .add (envelope )
212
210
node .poolMu .RLock ()
213
211
_ , found = node .messages [envelope .Hash ()]
214
212
node .poolMu .RUnlock ()
215
213
if found {
216
214
t .Fatalf ("message was added to cache" )
217
215
}
218
-
219
216
}
You can’t perform that action at this time.
0 commit comments