diff --git a/pkg/util/cache/BUILD b/pkg/util/cache/BUILD index 99afc255038..f85f78ba0d6 100644 --- a/pkg/util/cache/BUILD +++ b/pkg/util/cache/BUILD @@ -26,7 +26,10 @@ go_test( ], library = ":go_default_library", tags = ["automanaged"], - deps = ["//vendor:github.com/golang/groupcache/lru"], + deps = [ + "//pkg/util/clock:go_default_library", + "//vendor:github.com/golang/groupcache/lru", + ], ) filegroup( diff --git a/pkg/util/cache/lruexpirecache_test.go b/pkg/util/cache/lruexpirecache_test.go index 4c55c1aedd2..35c538d48b1 100644 --- a/pkg/util/cache/lruexpirecache_test.go +++ b/pkg/util/cache/lruexpirecache_test.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "k8s.io/kubernetes/pkg/util/clock" + "github.com/golang/groupcache/lru" ) @@ -43,8 +45,11 @@ func TestSimpleGet(t *testing.T) { } func TestExpiredGet(t *testing.T) { - c := NewLRUExpireCache(10) - c.Add("short-lived", "12345", 0*time.Second) + fakeClock := clock.NewFakeClock(time.Now()) + c := NewLRUExpireCacheWithClock(10, fakeClock) + c.Add("short-lived", "12345", 1*time.Millisecond) + // ensure the entry expired + fakeClock.Step(2 * time.Millisecond) expectNotEntry(t, c, "short-lived") }