From 926122c035a4f47a880db24d1a0be7ec129dd44d Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Tue, 12 Mar 2024 13:34:04 +0100 Subject: [PATCH] apiserver/storage/cacher: decrease of running time of TestEmptyWatchEventCache updates the test to wait 300 ms instead of 3s the watch was established otherwise we would be blocking on a call to cache.Watch(...) in addition to that, the tests are serial in nature, meaning that there is no other actor that could add items to the database, which could result in receiving new items. Before: go test -race -run TestEmptyWatchEventCache ok k8s.io/apiserver/pkg/storage/cacher 8.450s After: go test -race -run TestEmptyWatchEventCache ok k8s.io/apiserver/pkg/storage/cacher 2.635s --- .../apiserver/pkg/storage/cacher/cacher_whitebox_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go index 414307e1a0a..9a3bfcc068d 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go @@ -431,7 +431,14 @@ func TestEmptyWatchEventCache(t *testing.T) { if e, a := tt.expectedEvent.Object, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Expected: %#v, got: %#v", e, a) } - case <-time.After(3 * time.Second): + case <-time.After(1 * time.Second): + // the watch was established otherwise + // we would be blocking on cache.Watch(...) + // in addition to that, the tests are serial in nature, + // meaning that there is no other actor + // that could add items to the database, + // which could result in receiving new items. + // given that waiting 1s seems okay if tt.expectedEvent != nil { t.Errorf("Failed to get an event") }