From b7c74338e89be9828d4201e8ed482c5bda898de7 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Fri, 2 Oct 2020 14:11:21 -0500 Subject: [PATCH] test: e2e: fix race in pods test --- test/e2e/node/pods.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/e2e/node/pods.go b/test/e2e/node/pods.go index a5c1499ef3b..c68e04b6bad 100644 --- a/test/e2e/node/pods.go +++ b/test/e2e/node/pods.go @@ -263,6 +263,7 @@ var _ = SIGDescribe("Pods Extended", func() { start := time.Now() created := podClient.Create(pod) ch := make(chan []watch.Event) + waitForWatch := make(chan struct{}) go func() { defer ginkgo.GinkgoRecover() defer close(ch) @@ -275,6 +276,7 @@ var _ = SIGDescribe("Pods Extended", func() { return } defer w.Stop() + close(waitForWatch) events := []watch.Event{ {Type: watch.Added, Object: created}, } @@ -291,6 +293,10 @@ var _ = SIGDescribe("Pods Extended", func() { ch <- events }() + select { + case <-ch: // in case the goroutine above exits before establishing the watch + case <-waitForWatch: // when the watch is established + } t := time.Duration(rand.Intn(delay)) * time.Millisecond time.Sleep(t) err := podClient.Delete(context.TODO(), pod.Name, metav1.DeleteOptions{})