fix flake in TestTimeoutHeaders

This commit is contained in:
Abu Kashem 2022-02-07 10:34:20 -05:00
parent 9f791bbf5b
commit 2ae70e85d2
No known key found for this signature in database
GPG Key ID: 33A4FA7088DB68A9
2 changed files with 11 additions and 5 deletions

View File

@ -138,7 +138,7 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}()
}()
postTimeoutFn()
defer postTimeoutFn()
tw.timeout(err)
}
}

View File

@ -219,6 +219,7 @@ func TestTimeoutHeaders(t *testing.T) {
})
}
postTimeoutCh := make(chan struct{})
ts := httptest.NewServer(
withDeadline(
WithTimeout(
@ -226,13 +227,18 @@ func TestTimeoutHeaders(t *testing.T) {
h := w.Header()
// trigger the timeout
cancel()
// mutate response Headers
for j := 0; j < 1000; j++ {
// keep mutating response Headers until the request times out
for {
select {
case <-postTimeoutCh:
return
default:
h.Set("Test", "post")
}
}
}),
func(req *http.Request) (*http.Request, bool, func(), *apierrors.StatusError) {
return req, false, func() {}, apierrors.NewServerTimeout(schema.GroupResource{Group: "foo", Resource: "bar"}, "get", 0)
return req, false, func() { close(postTimeoutCh) }, apierrors.NewServerTimeout(schema.GroupResource{Group: "foo", Resource: "bar"}, "get", 0)
},
),
),