Deflake watchcache tests
This commit is contained in:
		@@ -1631,7 +1631,9 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	options := storage.ListOptions{
 | 
						options := storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// Limit is ignored when ResourceVersion is set to 0.
 | 
				
			||||||
 | 
							// Set it to consistent read.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(1, ""),
 | 
							Predicate:       pred(1, ""),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1654,7 +1656,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
 | 
				
			|||||||
	// no limit, should get two items
 | 
						// no limit, should get two items
 | 
				
			||||||
	out = &example.PodList{}
 | 
						out = &example.PodList{}
 | 
				
			||||||
	options = storage.ListOptions{
 | 
						options = storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// ResourceVersion should be unset when setting continuation token.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(0, continueFromSecondItem),
 | 
							Predicate:       pred(0, continueFromSecondItem),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1677,7 +1680,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
 | 
				
			|||||||
	// limit, should get two more pages
 | 
						// limit, should get two more pages
 | 
				
			||||||
	out = &example.PodList{}
 | 
						out = &example.PodList{}
 | 
				
			||||||
	options = storage.ListOptions{
 | 
						options = storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// ResourceVersion should be unset when setting continuation token.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(1, continueFromSecondItem),
 | 
							Predicate:       pred(1, continueFromSecondItem),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1699,7 +1703,8 @@ func RunTestListContinuation(ctx context.Context, t *testing.T, store storage.In
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	out = &example.PodList{}
 | 
						out = &example.PodList{}
 | 
				
			||||||
	options = storage.ListOptions{
 | 
						options = storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// ResourceVersion should be unset when setting continuation token.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(1, continueFromThirdItem),
 | 
							Predicate:       pred(1, continueFromThirdItem),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1815,7 +1820,9 @@ func RunTestListContinuationWithFilter(ctx context.Context, t *testing.T, store
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	options := storage.ListOptions{
 | 
						options := storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// Limit is ignored when ResourceVersion is set to 0.
 | 
				
			||||||
 | 
							// Set it to consistent read.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(2, ""),
 | 
							Predicate:       pred(2, ""),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1845,7 +1852,8 @@ func RunTestListContinuationWithFilter(ctx context.Context, t *testing.T, store
 | 
				
			|||||||
	// both read counters should be incremented for the singular calls they make in this case
 | 
						// both read counters should be incremented for the singular calls they make in this case
 | 
				
			||||||
	out = &example.PodList{}
 | 
						out = &example.PodList{}
 | 
				
			||||||
	options = storage.ListOptions{
 | 
						options = storage.ListOptions{
 | 
				
			||||||
		ResourceVersion: "0",
 | 
							// ResourceVersion should be unset when setting continuation token.
 | 
				
			||||||
 | 
							ResourceVersion: "",
 | 
				
			||||||
		Predicate:       pred(2, cont),
 | 
							Predicate:       pred(2, cont),
 | 
				
			||||||
		Recursive:       true,
 | 
							Recursive:       true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -2407,7 +2415,7 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
	err := store.GuaranteedUpdate(ctx, key, updatedPod, false, nil,
 | 
						err := store.GuaranteedUpdate(ctx, key, updatedPod, false, nil,
 | 
				
			||||||
		storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
							storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
				
			||||||
			pod := obj.(*example.Pod)
 | 
								pod := obj.(*example.Pod)
 | 
				
			||||||
			pod.Name = "foo-2"
 | 
								pod.Generation = 2
 | 
				
			||||||
			return pod, nil
 | 
								return pod, nil
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
		nil,
 | 
							nil,
 | 
				
			||||||
@@ -2424,7 +2432,7 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
	err = store.GuaranteedUpdate(ctx, key, updatedPod2, false, nil,
 | 
						err = store.GuaranteedUpdate(ctx, key, updatedPod2, false, nil,
 | 
				
			||||||
		storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
							storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
				
			||||||
			pod := obj.(*example.Pod)
 | 
								pod := obj.(*example.Pod)
 | 
				
			||||||
			if pod.Name != "foo-2" {
 | 
								if pod.Generation != 2 {
 | 
				
			||||||
				if sawConflict {
 | 
									if sawConflict {
 | 
				
			||||||
					t.Fatalf("unexpected second conflict")
 | 
										t.Fatalf("unexpected second conflict")
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@@ -2432,7 +2440,7 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
				// simulated stale object - return a conflict
 | 
									// simulated stale object - return a conflict
 | 
				
			||||||
				return nil, apierrors.NewConflict(example.SchemeGroupVersion.WithResource("pods").GroupResource(), "name", errors.New("foo"))
 | 
									return nil, apierrors.NewConflict(example.SchemeGroupVersion.WithResource("pods").GroupResource(), "name", errors.New("foo"))
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			pod.Name = "foo-3"
 | 
								pod.Generation = 3
 | 
				
			||||||
			return pod, nil
 | 
								return pod, nil
 | 
				
			||||||
		}),
 | 
							}),
 | 
				
			||||||
		originalPod,
 | 
							originalPod,
 | 
				
			||||||
@@ -2440,8 +2448,8 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		t.Fatalf("unexpected error: %v", err)
 | 
							t.Fatalf("unexpected error: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if updatedPod2.Name != "foo-3" {
 | 
						if updatedPod2.Generation != 3 {
 | 
				
			||||||
		t.Errorf("unexpected pod name: %q", updatedPod2.Name)
 | 
							t.Errorf("unexpected pod generation: %q", updatedPod2.Generation)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Third, update using a current version as the suggestion.
 | 
						// Third, update using a current version as the suggestion.
 | 
				
			||||||
@@ -2452,14 +2460,8 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
	err = store.GuaranteedUpdate(ctx, key, updatedPod3, false, nil,
 | 
						err = store.GuaranteedUpdate(ctx, key, updatedPod3, false, nil,
 | 
				
			||||||
		storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
							storage.SimpleUpdate(func(obj runtime.Object) (runtime.Object, error) {
 | 
				
			||||||
			pod := obj.(*example.Pod)
 | 
								pod := obj.(*example.Pod)
 | 
				
			||||||
			if pod.Name != updatedPod2.Name || pod.ResourceVersion != updatedPod2.ResourceVersion {
 | 
								if pod.Generation != updatedPod2.Generation || pod.ResourceVersion != updatedPod2.ResourceVersion {
 | 
				
			||||||
				t.Errorf(
 | 
									t.Logf("stale object (rv=%s), expected rv=%s", pod.ResourceVersion, updatedPod2.ResourceVersion)
 | 
				
			||||||
					"unexpected live object (name=%s, rv=%s), expected name=%s, rv=%s",
 | 
					 | 
				
			||||||
					pod.Name,
 | 
					 | 
				
			||||||
					pod.ResourceVersion,
 | 
					 | 
				
			||||||
					updatedPod2.Name,
 | 
					 | 
				
			||||||
					updatedPod2.ResourceVersion,
 | 
					 | 
				
			||||||
				)
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			attempts++
 | 
								attempts++
 | 
				
			||||||
			return nil, fmt.Errorf("validation or admission error")
 | 
								return nil, fmt.Errorf("validation or admission error")
 | 
				
			||||||
@@ -2469,8 +2471,10 @@ func RunTestGuaranteedUpdateWithSuggestionAndConflict(ctx context.Context, t *te
 | 
				
			|||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		t.Fatalf("expected error, got none")
 | 
							t.Fatalf("expected error, got none")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if attempts != 1 {
 | 
						// Implementations of the storage interface are allowed to ignore the suggestion,
 | 
				
			||||||
		t.Errorf("expected 1 attempt, got %d", attempts)
 | 
						// in which case two attempts are possible.
 | 
				
			||||||
 | 
						if attempts > 2 {
 | 
				
			||||||
 | 
							t.Errorf("update function should have been called at most twice, called %d", attempts)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user