mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 21:53:52 +00:00
use fake clock in lruexpiration cache test
This commit is contained in:
5
pkg/util/cache/BUILD
vendored
5
pkg/util/cache/BUILD
vendored
@@ -26,7 +26,10 @@ go_test(
|
|||||||
],
|
],
|
||||||
library = ":go_default_library",
|
library = ":go_default_library",
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = ["//vendor:github.com/golang/groupcache/lru"],
|
deps = [
|
||||||
|
"//pkg/util/clock:go_default_library",
|
||||||
|
"//vendor:github.com/golang/groupcache/lru",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
9
pkg/util/cache/lruexpirecache_test.go
vendored
9
pkg/util/cache/lruexpirecache_test.go
vendored
@@ -20,6 +20,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/util/clock"
|
||||||
|
|
||||||
"github.com/golang/groupcache/lru"
|
"github.com/golang/groupcache/lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,8 +45,11 @@ func TestSimpleGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExpiredGet(t *testing.T) {
|
func TestExpiredGet(t *testing.T) {
|
||||||
c := NewLRUExpireCache(10)
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
c.Add("short-lived", "12345", 0*time.Second)
|
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")
|
expectNotEntry(t, c, "short-lived")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user