Merge pull request #135002 from p0lyn0mial/upstream-watchlist-unsupported-wl-client-tools-watch-test

client-go/tools/watch/test: wrap the LW with toListWatcherWithUnSupportedWatchListSemantics

Kubernetes-commit: f1989437f8b4c7725e8c603d6c29693b89298f37
This commit is contained in:
Kubernetes Publisher
2025-10-31 04:50:03 -07:00
2 changed files with 27 additions and 13 deletions

View File

@@ -387,7 +387,7 @@ func TestNewInformerWatcher(t *testing.T) {
func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) {
listCalls := 0
watchCalls := 0
lw := &cache.ListWatch{
lw := toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
retval := &corev1.SecretList{}
if listCalls == 0 {
@@ -413,7 +413,7 @@ func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) {
watchCalls++
return w, nil
},
}
})
//nolint:logcheck // Intentionally uses the older API.
_, _, w, done := NewIndexerInformerWatcher(lw, &corev1.Secret{})
defer w.Stop()
@@ -464,3 +464,17 @@ func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) {
t.Fatalf("expected at least 1 watch call, got %d", watchCalls)
}
}
type listWatchWithUnSupportedWatchListSemanticsWrapper struct {
*cache.ListWatch
}
func (lw listWatchWithUnSupportedWatchListSemanticsWrapper) IsWatchListSemanticsUnSupported() bool {
return true
}
func toListWatcherWithUnSupportedWatchListSemantics(lw *cache.ListWatch) cache.ListerWatcher {
return listWatchWithUnSupportedWatchListSemanticsWrapper{
lw,
}
}

View File

@@ -189,7 +189,7 @@ func TestUntilWithSync(t *testing.T) {
// FIXME: test preconditions
tt := []struct {
name string
lw *cache.ListWatch
lw cache.ListerWatcher
preconditionFunc PreconditionFunc
conditionFunc ConditionFunc
expectedErr error
@@ -197,14 +197,14 @@ func TestUntilWithSync(t *testing.T) {
}{
{
name: "doesn't wait for sync with no precondition",
lw: &cache.ListWatch{
lw: toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
select {}
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
select {}
},
},
}),
preconditionFunc: nil,
conditionFunc: func(e watch.Event) (bool, error) {
return true, nil
@@ -214,14 +214,14 @@ func TestUntilWithSync(t *testing.T) {
},
{
name: "waits indefinitely with precondition if it can't sync",
lw: &cache.ListWatch{
lw: toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
select {}
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
select {}
},
},
}),
preconditionFunc: func(store cache.Store) (bool, error) {
return true, nil
},
@@ -233,17 +233,17 @@ func TestUntilWithSync(t *testing.T) {
},
{
name: "precondition can stop the loop",
lw: func() *cache.ListWatch {
lw: func() cache.ListerWatcher {
fakeclient := fakeclient.NewSimpleClientset(&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "first"}})
return &cache.ListWatch{
return toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return fakeclient.CoreV1().Secrets("").List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return fakeclient.CoreV1().Secrets("").Watch(context.TODO(), options)
},
}
})
}(),
preconditionFunc: func(store cache.Store) (bool, error) {
_, exists, err := store.Get(&metav1.ObjectMeta{Namespace: "", Name: "first"})
@@ -263,17 +263,17 @@ func TestUntilWithSync(t *testing.T) {
},
{
name: "precondition lets it proceed to regular condition",
lw: func() *cache.ListWatch {
lw: func() cache.ListerWatcher {
fakeclient := fakeclient.NewSimpleClientset(&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "first"}})
return &cache.ListWatch{
return toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return fakeclient.CoreV1().Secrets("").List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return fakeclient.CoreV1().Secrets("").Watch(context.TODO(), options)
},
}
})
}(),
preconditionFunc: func(store cache.Store) (bool, error) {
return false, nil