Merge pull request #107992 from tkashem/flake-timeout

fix flake in TestTimeoutHeaders
This commit is contained in:
Kubernetes Prow Robot 2022-02-07 19:20:53 -08:00 committed by GitHub
commit 5cee90c305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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++ {
h.Set("Test", "post")
// 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)
},
),
),