Skip to content

Commit e59988d

Browse files
committed
Fix flaking TestStoreListResourceVersion
1 parent 1815a14 commit e59988d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,14 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
24462446
if err != nil {
24472447
t.Fatalf("Couldn't create cacher: %v", err)
24482448
}
2449+
if utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
2450+
// The tests assume that Get/GetList/Watch calls shouldn't fail.
2451+
// However, 429 error can now be returned if watchcache is under initialization.
2452+
// To avoid rewriting all tests, we wait for watchcache to initialize.
2453+
if err := cacher.Wait(context.Background()); err != nil {
2454+
t.Fatal(err)
2455+
}
2456+
}
24492457
d := destroyFunc
24502458
s = cacher
24512459
destroyFunc = func() {

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,11 @@ func (c *Cacher) waitUntilWatchCacheFreshAndForceAllEvents(ctx context.Context,
13581358
return nil
13591359
}
13601360

1361+
// Wait blocks until the cacher is Ready or Stopped, it returns an error if Stopped.
1362+
func (c *Cacher) Wait(ctx context.Context) error {
1363+
return c.ready.wait(ctx)
1364+
}
1365+
13611366
// errWatcher implements watch.Interface to return a single error
13621367
type errWatcher struct {
13631368
result chan watch.Event

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ func testSetupWithEtcdServer(t *testing.T, opts ...setupOption) (context.Context
472472
if utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
473473
// The tests assume that Get/GetList/Watch calls shouldn't fail.
474474
// However, 429 error can now be returned if watchcache is under initialization.
475-
// To avoid rewriting all tests, we wait for watcache to initialize.
476-
if err := cacher.ready.wait(ctx); err != nil {
475+
// To avoid rewriting all tests, we wait for watchcache to initialize.
476+
if err := cacher.Wait(ctx); err != nil {
477477
t.Fatal(err)
478478
}
479479
}

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func newTestCacher(s storage.Interface) (*Cacher, storage.Versioner, error) {
9393
// The tests assume that Get/GetList/Watch calls shouldn't fail.
9494
// However, 429 error can now be returned if watchcache is under initialization.
9595
// To avoid rewriting all tests, we wait for watcache to initialize.
96-
if err := cacher.ready.wait(context.Background()); err != nil {
96+
if err := cacher.Wait(context.Background()); err != nil {
9797
return nil, storage.APIObjectVersioner{}, err
9898
}
9999
}

0 commit comments

Comments
 (0)