From 3bc43e0d191c4f0fdbac90510c04f04ac63a70fe Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Tue, 12 Jun 2018 13:47:00 -0700 Subject: [PATCH] Flakey test fix: TestWorkQueueHealthCheck I believe this shoud fix this flakey test --- pkg/util/workerqueue/workerqueue_test.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/util/workerqueue/workerqueue_test.go b/pkg/util/workerqueue/workerqueue_test.go index beff91cb00..866f33093b 100644 --- a/pkg/util/workerqueue/workerqueue_test.go +++ b/pkg/util/workerqueue/workerqueue_test.go @@ -121,14 +121,26 @@ func TestWorkQueueHealthCheck(t *testing.T) { url := server.URL + "/live" f := func(t *testing.T, url string, status int) { - resp, err := http.Get(url) - assert.Nil(t, err) - defer resp.Body.Close() // nolint: errcheck - body, err := ioutil.ReadAll(resp.Body) + // sometimes the http server takes a bit to start up + err := wait.PollImmediate(time.Second, 5*time.Second, func() (bool, error) { + resp, err := http.Get(url) + assert.Nil(t, err) + defer resp.Body.Close() // nolint: errcheck + + if status != resp.StatusCode { + return false, nil + } + + body, err := ioutil.ReadAll(resp.Body) + assert.Nil(t, err) + assert.Equal(t, status, resp.StatusCode) + assert.Equal(t, []byte("{}\n"), body) + + return true, nil + }) + assert.Nil(t, err) - assert.Equal(t, status, resp.StatusCode) - assert.Equal(t, []byte("{}\n"), body) } f(t, url, http.StatusOK)