From 866e7ee8325ac0144225cc8efc271d2b38968d86 Mon Sep 17 00:00:00 2001 From: nisdas Date: Wed, 15 Mar 2023 18:47:58 +0800 Subject: [PATCH 1/2] fix bug --- timecache/first_seen_cache_test.go | 6 ++++-- timecache/util.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/timecache/first_seen_cache_test.go b/timecache/first_seen_cache_test.go index 858a4617..59d2a59e 100644 --- a/timecache/first_seen_cache_test.go +++ b/timecache/first_seen_cache_test.go @@ -26,8 +26,10 @@ func TestFirstSeenCacheExpire(t *testing.T) { } time.Sleep(2 * time.Second) - if tc.Has(fmt.Sprint(0)) { - t.Fatal("should have dropped this from the cache already") + for i := 0; i < 10; i++ { + if tc.Has(fmt.Sprint(i)) { + t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i)) + } } } diff --git a/timecache/util.go b/timecache/util.go index aaf35c35..eaf92b34 100644 --- a/timecache/util.go +++ b/timecache/util.go @@ -9,7 +9,7 @@ import ( var backgroundSweepInterval = time.Minute func background(ctx context.Context, lk sync.Locker, m map[string]time.Time) { - ticker := time.NewTimer(backgroundSweepInterval) + ticker := time.NewTicker(backgroundSweepInterval) defer ticker.Stop() for { From 6a1f38c889942a1ec988d504c8c4b579b2a0186e Mon Sep 17 00:00:00 2001 From: nisdas Date: Wed, 15 Mar 2023 19:33:46 +0800 Subject: [PATCH 2/2] add for last seen cache --- timecache/last_seen_cache_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/timecache/last_seen_cache_test.go b/timecache/last_seen_cache_test.go index 4005df58..45220267 100644 --- a/timecache/last_seen_cache_test.go +++ b/timecache/last_seen_cache_test.go @@ -25,8 +25,10 @@ func TestLastSeenCacheExpire(t *testing.T) { } time.Sleep(2 * time.Second) - if tc.Has(fmt.Sprint(0)) { - t.Fatal("should have dropped this from the cache already") + for i := 0; i < 11; i++ { + if tc.Has(fmt.Sprint(i)) { + t.Fatalf("should have dropped this key: %s from the cache already", fmt.Sprint(i)) + } } }