Merge pull request #118539 from benluddy/timeout-filter-flake

Ensure timeout test handlers don't complete before timing out.
This commit is contained in:
Kubernetes Prow Robot 2023-06-13 09:21:58 -07:00 committed by GitHub
commit 666fc23fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,6 +272,8 @@ func TestTimeoutRequestHeaders(t *testing.T) {
}) })
} }
testDone := make(chan struct{})
defer close(testDone)
ts := httptest.NewServer( ts := httptest.NewServer(
withDeadline( withDeadline(
WithTimeoutForNonLongRunningRequests( WithTimeoutForNonLongRunningRequests(
@ -280,8 +282,13 @@ func TestTimeoutRequestHeaders(t *testing.T) {
cancel() cancel()
// mutate request Headers // mutate request Headers
// Authorization filter does it for example // Authorization filter does it for example
for j := 0; j < 10000; j++ { for {
req.Header.Set("Test", "post") select {
case <-testDone:
return
default:
req.Header.Set("Test", "post")
}
} }
}), }),
func(r *http.Request, requestInfo *request.RequestInfo) bool { func(r *http.Request, requestInfo *request.RequestInfo) bool {
@ -301,8 +308,8 @@ func TestTimeoutRequestHeaders(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if res.StatusCode != http.StatusGatewayTimeout { if actual, expected := res.StatusCode, http.StatusGatewayTimeout; actual != expected {
t.Errorf("got res.StatusCde %d; expected %d", res.StatusCode, http.StatusServiceUnavailable) t.Errorf("got status code %d; expected %d", actual, expected)
} }
res.Body.Close() res.Body.Close()
} }
@ -323,6 +330,8 @@ func TestTimeoutWithLogging(t *testing.T) {
}) })
} }
testDone := make(chan struct{})
defer close(testDone)
ts := httptest.NewServer( ts := httptest.NewServer(
WithHTTPLogging( WithHTTPLogging(
withDeadline( withDeadline(
@ -332,8 +341,13 @@ func TestTimeoutWithLogging(t *testing.T) {
cancel() cancel()
// mutate request Headers // mutate request Headers
// Authorization filter does it for example // Authorization filter does it for example
for j := 0; j < 10000; j++ { for {
req.Header.Set("Test", "post") select {
case <-testDone:
return
default:
req.Header.Set("Test", "post")
}
} }
}), }),
func(r *http.Request, requestInfo *request.RequestInfo) bool { func(r *http.Request, requestInfo *request.RequestInfo) bool {
@ -354,8 +368,8 @@ func TestTimeoutWithLogging(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if res.StatusCode != http.StatusGatewayTimeout { if actual, expected := res.StatusCode, http.StatusGatewayTimeout; actual != expected {
t.Errorf("got res.StatusCode %d; expected %d", res.StatusCode, http.StatusServiceUnavailable) t.Errorf("got status code %d; expected %d", actual, expected)
} }
res.Body.Close() res.Body.Close()
} }