Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky test fix: TestWorkQueueHealthCheck #260

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pkg/util/workerqueue/workerqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down