From 5fd0162a8ac30613e9190da32bc5f6c456d430f5 Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 7 Mar 2017 08:53:29 -0500 Subject: [PATCH] deflake TestPatch by waiting for cache --- test/integration/client/client_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/integration/client/client_test.go b/test/integration/client/client_test.go index 2b9da7dfa8..03c53d4710 100644 --- a/test/integration/client/client_test.go +++ b/test/integration/client/client_test.go @@ -28,6 +28,7 @@ import ( "time" apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" @@ -285,6 +286,24 @@ func TestPatch(t *testing.T) { } else { t.Logf("%v", string(jsonObj)) } + + obj, err := result.Get() + if err != nil { + t.Fatal(err) + } + metadata, err := meta.Accessor(obj) + if err != nil { + t.Fatal(err) + } + // this call waits for the resourceVersion to be reached in the cache before returning. We need to do this because + // the patch gets its initial object from the storage, and the cache serves that. If it is out of date, + // then our initial patch is applied to an old resource version, which conflicts and then the updated object shows + // a conflicting diff, which permanently fails the patch. This gives expected stability in the patch without + // retrying on an known number of conflicts below in the test. + if _, err := c.Core().Pods(ns.Name).Get(name, metav1.GetOptions{ResourceVersion: metadata.GetResourceVersion()}); err != nil { + t.Fatal(err) + } + return nil }