@ -179,9 +179,7 @@ func TestMessageExpiration(t *testing.T) {
node := startTestCluster ( 1 ) [ 0 ]
node := startTestCluster ( 1 ) [ 0 ]
message := NewMessage ( [ ] byte ( "expiring message" ) )
message := NewMessage ( [ ] byte ( "expiring message" ) )
envelope , err := message . Wrap ( DefaultPoW , Options {
envelope , err := message . Wrap ( DefaultPoW , Options { TTL : time . Second } )
TTL : time . Second ,
} )
if err != nil {
if err != nil {
t . Fatalf ( "failed to wrap message: %v" , err )
t . Fatalf ( "failed to wrap message: %v" , err )
}
}
@ -198,16 +196,16 @@ func TestMessageExpiration(t *testing.T) {
}
}
// Wait for expiration and check cache again
// Wait for expiration and check cache again
time . Sleep ( time . Second ) // wait for expiration
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 ( )
node . poolMu . RLock ( )
_ , found = node . messages [ envelope . Hash ( ) ]
_ , found = node . messages [ envelope . Hash ( ) ]
node . poolMu . RUnlock ( )
node . poolMu . RUnlock ( )
if found {
if found {
t . Fatalf ( "message not expired from cache" )
t . Fatalf ( "message not expired from cache" )
}
}
// Check that adding an expired envelope doesn't do anything.
node . add ( envelope )
node . add ( envelope )
node . poolMu . RLock ( )
node . poolMu . RLock ( )
_ , found = node . messages [ envelope . Hash ( ) ]
_ , found = node . messages [ envelope . Hash ( ) ]
@ -215,5 +213,4 @@ func TestMessageExpiration(t *testing.T) {
if found {
if found {
t . Fatalf ( "message was added to cache" )
t . Fatalf ( "message was added to cache" )
}
}
}
}