From e7e2123feb2f1957be490a21aa606cb2dc718432 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Fri, 20 Sep 2024 09:37:53 +0200 Subject: [PATCH] pkg/storage/testing/watcher_tests: RunWatchSemantics checks if the storage has been primed with init data --- .../pkg/storage/testing/watcher_tests.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go b/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go index 89672d80624..952da81728e 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/testing/watcher_tests.go @@ -1460,6 +1460,21 @@ func RunWatchSemantics(ctx context.Context, t *testing.T, store storage.Interfac createdPods = append(createdPods, out) } + if len(createdPods) > 0 { + // this list call ensures that the cache has seen the created pods. + // this makes the watch request below deterministic. + listObject := &example.PodList{} + opts := storage.ListOptions{ + Predicate: storage.Everything, + Recursive: true, + ResourceVersion: createdPods[len(createdPods)-1].ResourceVersion, + ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, + } + err := store.GetList(ctx, fmt.Sprintf("/pods/%s", ns), opts, listObject) + require.NoError(t, err) + require.Len(t, listObject.Items, len(createdPods)) + } + if scenario.useCurrentRV { currentStorageRV, err := storage.GetCurrentResourceVersionFromStorage(ctx, store, func() runtime.Object { return &example.PodList{} }, "/pods", "") require.NoError(t, err)