Update expiration test

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2019-10-03 13:38:59 -06:00
committed by Derek Collison
parent 09c1acc36c
commit 9214fa2995

View File

@@ -144,17 +144,30 @@ func TestMemStoreAgeLimit(t *testing.T) {
if stats.Msgs != uint64(toStore) {
t.Fatalf("Expected %d msgs, got %d", toStore, stats.Msgs)
}
checkExpired := func(t *testing.T) {
t.Helper()
checkFor(t, time.Second, maxAge, func() error {
stats = ms.Stats()
if stats.Msgs != 0 {
return fmt.Errorf("Expected no msgs, got %d", stats.Msgs)
}
if stats.Bytes != 0 {
return fmt.Errorf("Expected no bytes, got %d", stats.Bytes)
}
return nil
})
}
// Let them expire
checkFor(t, time.Second, maxAge, func() error {
stats = ms.Stats()
if stats.Msgs != 0 {
return fmt.Errorf("Expected no msgs, got %d", stats.Msgs)
}
if stats.Bytes != 0 {
return fmt.Errorf("Expected no bytes, got %d", stats.Bytes)
}
return nil
})
checkExpired(t)
// Now add some more and make sure that timer will fire again.
for i := 0; i < toStore; i++ {
ms.StoreMsg(subj, msg)
}
stats = ms.Stats()
if stats.Msgs != uint64(toStore) {
t.Fatalf("Expected %d msgs, got %d", toStore, stats.Msgs)
}
checkExpired(t)
}
func TestMemStoreTimeStamps(t *testing.T) {