Skip to content

Commit

Permalink
test: cache expire interval (#1160)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Mar 14, 2022
1 parent 9155d1b commit 7707e08
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ func TestCache(t *testing.T) {
func TestCacheTimes(t *testing.T) {
var found bool

tc := New(50*time.Millisecond, 1*time.Millisecond)
tc := New(100*time.Millisecond, 1*time.Millisecond)
tc.Set("a", 1, DefaultExpiration)
tc.Set("b", 2, NoExpiration)
tc.Set("c", 3, 20*time.Millisecond)
tc.Set("d", 4, 70*time.Millisecond)
tc.Set("c", 3, 40*time.Millisecond)
tc.Set("d", 4, 140*time.Millisecond)

<-time.After(25 * time.Millisecond)
<-time.After(50 * time.Millisecond)
_, found = tc.Get("c")
if found {
t.Error("Found c when it should have been automatically deleted")
}

<-time.After(30 * time.Millisecond)
<-time.After(80 * time.Millisecond)
_, found = tc.Get("a")
if found {
t.Error("Found a when it should have been automatically deleted")
Expand All @@ -122,7 +122,7 @@ func TestCacheTimes(t *testing.T) {
t.Error("Did not find d even though it was set to expire later than the default")
}

<-time.After(20 * time.Millisecond)
<-time.After(40 * time.Millisecond)
_, found = tc.Get("d")
if found {
t.Error("Found d when it should have been automatically deleted (later than the default)")
Expand Down

0 comments on commit 7707e08

Please sign in to comment.