apiserver/storage/cacher: decrease running time of TestCacheWatcherDrainingNoBookmarkAfterResourceVersionReceived

before:
go test -v -race -count 1 -run ^TestCacheWatcherDrainingNoBookmarkAfterResourceVersionReceived$
ok  	k8s.io/apiserver/pkg/storage/cacher	3.792s

after:
go test -v -race -count 1 -run ^TestCacheWatcherDrainingNoBookmarkAfterResourceVersionReceived$
ok  	k8s.io/apiserver/pkg/storage/cacher	1.783s
This commit is contained in:
Lukasz Szaszkiewicz 2024-03-14 10:44:51 +01:00
parent 6680700b5d
commit d21b86d53a

View File

@ -499,10 +499,22 @@ func TestCacheWatcherDrainingNoBookmarkAfterResourceVersionReceived(t *testing.T
w = newCacheWatcher(0, filter, forget, storage.APIObjectVersioner{}, time.Now(), true, schema.GroupResource{Resource: "pods"}, "")
w.setBookmarkAfterResourceVersion(10)
go w.processInterval(context.Background(), intervalFromEvents(initEvents), 0)
if w.add(&watchCacheEvent{Object: &v1.Pod{}}, time.NewTimer(1*time.Second)) {
// get an event so that
// we know the w.processInterval
// has been scheduled, and
// it will be blocked on
// sending the other event
// to the result chan
<-w.ResultChan()
// now, once we know, the processInterval
// is waiting add another event that will time out
// and start the cleanup process
if w.add(&watchCacheEvent{Object: &v1.Pod{}}, time.NewTimer(10*time.Millisecond)) {
t.Fatal("expected the add method to fail")
}
if err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
if err := wait.PollUntilContextTimeout(context.Background(), 100*time.Millisecond, 5*time.Second, true, func(_ context.Context) (bool, error) {
lock.RLock()
defer lock.RUnlock()
return count == 2, nil