Merge pull request #122676 from p0lyn0mial/upstream-watch-cache-init-events-ordering
apiserver/storage: improve RunWatchSemanticInitialEventsExtended test
This commit is contained in:
		@@ -1505,31 +1505,36 @@ func RunWatchSemantics(ctx context.Context, t *testing.T, store storage.Interfac
 | 
				
			|||||||
// by adding the pod to a different ns to advance the global RV
 | 
					// by adding the pod to a different ns to advance the global RV
 | 
				
			||||||
func RunWatchSemanticInitialEventsExtended(ctx context.Context, t *testing.T, store storage.Interface) {
 | 
					func RunWatchSemanticInitialEventsExtended(ctx context.Context, t *testing.T, store storage.Interface) {
 | 
				
			||||||
	trueVal := true
 | 
						trueVal := true
 | 
				
			||||||
	expectedInitialEventsInStrictOrder := func(firstPod, secondPod *example.Pod) []watch.Event {
 | 
						expectedInitialEventsInStrictOrder := func(initialPods []*example.Pod, globalResourceVersion string) []watch.Event {
 | 
				
			||||||
		return []watch.Event{
 | 
							watchEvents := []watch.Event{}
 | 
				
			||||||
			{Type: watch.Added, Object: firstPod},
 | 
							for _, initialPod := range initialPods {
 | 
				
			||||||
			{Type: watch.Bookmark, Object: &example.Pod{
 | 
								watchEvents = append(watchEvents, watch.Event{Type: watch.Added, Object: initialPod})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							watchEvents = append(watchEvents, watch.Event{Type: watch.Bookmark, Object: &example.Pod{
 | 
				
			||||||
			ObjectMeta: metav1.ObjectMeta{
 | 
								ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					ResourceVersion: secondPod.ResourceVersion,
 | 
									ResourceVersion: globalResourceVersion,
 | 
				
			||||||
				Annotations:     map[string]string{"k8s.io/initial-events-end": "true"},
 | 
									Annotations:     map[string]string{"k8s.io/initial-events-end": "true"},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			}},
 | 
							}})
 | 
				
			||||||
		}
 | 
							return watchEvents
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, true)()
 | 
						defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, true)()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						initialPods := []*example.Pod{}
 | 
				
			||||||
	ns := "ns-foo"
 | 
						ns := "ns-foo"
 | 
				
			||||||
	pod := makePod("1")
 | 
						for _, initialPod := range []*example.Pod{makePod("1"), makePod("2"), makePod("3"), makePod("4"), makePod("5")} {
 | 
				
			||||||
	pod.Namespace = ns
 | 
							initialPod.Namespace = ns
 | 
				
			||||||
	firstPod := &example.Pod{}
 | 
							out := &example.Pod{}
 | 
				
			||||||
	err := store.Create(ctx, computePodKey(pod), pod, firstPod, 0)
 | 
							err := store.Create(ctx, computePodKey(initialPod), initialPod, out, 0)
 | 
				
			||||||
		require.NoError(t, err, "failed to add a pod: %v")
 | 
							require.NoError(t, err, "failed to add a pod: %v")
 | 
				
			||||||
 | 
							initialPods = append(initialPods, out)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// add the pod to a different ns to advance the global RV
 | 
						// add the pod to a different ns to advance the global RV
 | 
				
			||||||
	pod = makePod("2")
 | 
						pod := makePod("1")
 | 
				
			||||||
	pod.Namespace = "other-ns-foo"
 | 
						pod.Namespace = "other-ns-foo"
 | 
				
			||||||
	secondPod := &example.Pod{}
 | 
						otherNsPod := &example.Pod{}
 | 
				
			||||||
	err = store.Create(ctx, computePodKey(pod), pod, secondPod, 0)
 | 
						err := store.Create(ctx, computePodKey(pod), pod, otherNsPod, 0)
 | 
				
			||||||
	require.NoError(t, err, "failed to add a pod: %v")
 | 
						require.NoError(t, err, "failed to add a pod: %v")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts := storage.ListOptions{Predicate: storage.Everything, Recursive: true}
 | 
						opts := storage.ListOptions{Predicate: storage.Everything, Recursive: true}
 | 
				
			||||||
@@ -1542,7 +1547,7 @@ func RunWatchSemanticInitialEventsExtended(ctx context.Context, t *testing.T, st
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// make sure we only get initial events from the first ns
 | 
						// make sure we only get initial events from the first ns
 | 
				
			||||||
	// followed by the bookmark with the global RV
 | 
						// followed by the bookmark with the global RV
 | 
				
			||||||
	testCheckResultsInStrictOrder(t, w, expectedInitialEventsInStrictOrder(firstPod, secondPod))
 | 
						testCheckResultsInStrictOrder(t, w, expectedInitialEventsInStrictOrder(initialPods, otherNsPod.ResourceVersion))
 | 
				
			||||||
	testCheckNoMoreResults(t, w)
 | 
						testCheckNoMoreResults(t, w)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user