Deflake TestPrepareRun

This commit is contained in:
Jordan Liggitt 2021-03-06 19:46:00 -05:00
parent f8151b121f
commit ba4aade23a

View File

@ -40,6 +40,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/version"
"k8s.io/apiserver/pkg/apis/example"
examplev1 "k8s.io/apiserver/pkg/apis/example/v1"
@ -320,6 +321,7 @@ func TestPrepareRun(t *testing.T) {
server := httptest.NewServer(s.Handler.Director)
defer server.Close()
done := make(chan struct{})
defer close(done)
s.PrepareRun()
s.RunPostStartHooks(done)
@ -329,10 +331,19 @@ func TestPrepareRun(t *testing.T) {
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
// healthz checks are installed in PrepareRun
resp, err = http.Get(server.URL + "/healthz")
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
// wait for health (max-in-flight-filter is initialized asynchronously, can take a few milliseconds to initialize)
assert.NoError(wait.PollImmediate(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
// healthz checks are installed in PrepareRun
resp, err = http.Get(server.URL + "/healthz")
assert.NoError(err)
data, _ := ioutil.ReadAll(resp.Body)
if http.StatusOK != resp.StatusCode {
t.Logf("got %d", resp.StatusCode)
t.Log(string(data))
return false, nil
}
return true, nil
}))
resp, err = http.Get(server.URL + "/healthz/ping")
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)