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

Ensure timeout test handlers don't complete before timing out. #118539

Merged
merged 1 commit into from Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 22 additions & 8 deletions staging/src/k8s.io/apiserver/pkg/server/filters/timeout_test.go
Expand Up @@ -272,6 +272,8 @@ func TestTimeoutRequestHeaders(t *testing.T) {
})
}

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

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