Skip to content

Commit 017a6fe

Browse files
committed
Deflake TestListResourceVersion0
1 parent c53ce48 commit 017a6fe

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

test/integration/apiserver/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ go_test(
5454
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/protobuf:go_default_library",
5555
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library",
5656
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
57+
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
5758
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
5859
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
5960
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",

test/integration/apiserver/apiserver_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
5050
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
5151
"k8s.io/apimachinery/pkg/types"
52+
"k8s.io/apimachinery/pkg/util/wait"
5253
"k8s.io/apimachinery/pkg/watch"
5354
"k8s.io/apiserver/pkg/features"
5455
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -548,6 +549,20 @@ func TestListResourceVersion0(t *testing.T) {
548549
}
549550
}
550551

552+
if tc.watchCacheEnabled {
553+
// poll until the watch cache has the full list in memory
554+
err := wait.PollImmediate(time.Second, wait.ForeverTestTimeout, func() (bool, error) {
555+
list, err := clientSet.AppsV1().ReplicaSets(ns.Name).List(context.Background(), metav1.ListOptions{ResourceVersion: "0"})
556+
if err != nil {
557+
return false, err
558+
}
559+
return len(list.Items) == 10, nil
560+
})
561+
if err != nil {
562+
t.Fatalf("error waiting for watch cache to observe the full list: %v", err)
563+
}
564+
}
565+
551566
pagerFn := func(opts metav1.ListOptions) (runtime.Object, error) {
552567
return rsClient.List(context.TODO(), opts)
553568
}

0 commit comments

Comments
 (0)