Skip to content

Commit 4a86c90

Browse files
committed
Fix flaky TestDestroyPodInflight test
Fixes three issues causing test flakiness: 1. Fix response body reading - use io.ReadAll instead of incorrectly casting res.Body to string 2. Add proper response body cleanup with defer 3. Delete Route before Configuration to prevent reconciliation errors during teardown (fixes "revision not found" and "failed to fetch loadbalancer" errors in CI logs) The test now correctly validates that in-flight requests complete successfully during graceful shutdown.
1 parent cf48bab commit 4a86c90

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/e2e/destroypod_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package e2e
2222
import (
2323
"context"
2424
"fmt"
25+
"io"
2526
"net/http"
2627
"net/url"
2728
"strconv"
@@ -128,12 +129,19 @@ func TestDestroyPodInflight(t *testing.T) {
128129
if err != nil {
129130
return err
130131
}
132+
defer res.Body.Close()
131133

132134
if res.StatusCode != http.StatusOK {
133135
return fmt.Errorf("expected response to have status 200, had %d", res.StatusCode)
134136
}
137+
138+
bodyBytes, err := io.ReadAll(res.Body)
139+
if err != nil {
140+
return fmt.Errorf("failed to read response body: %w", err)
141+
}
142+
135143
expectedBody := fmt.Sprintf("Slept for %d milliseconds", timeoutRequestDuration.Milliseconds())
136-
gotBody := string(res.Body)
144+
gotBody := string(bodyBytes)
137145
if gotBody != expectedBody {
138146
return fmt.Errorf("unexpected body, expected: %q got: %q", expectedBody, gotBody)
139147
}
@@ -144,8 +152,16 @@ func TestDestroyPodInflight(t *testing.T) {
144152
// Give the request a bit of time to be established and reach the pod.
145153
time.Sleep(timeoutRequestDuration / 2)
146154

147-
t.Log("Destroying the configuration (also destroys the pods)")
148-
return clients.ServingClient.Configs.Delete(egCtx, names.Config, metav1.DeleteOptions{})
155+
t.Log("Destroying the route and configuration (also destroys the pods)")
156+
// Delete the Route first to prevent reconciliation errors during cleanup
157+
if err := clients.ServingClient.Routes.Delete(egCtx, names.Route, metav1.DeleteOptions{}); err != nil {
158+
return fmt.Errorf("failed to delete route: %w", err)
159+
}
160+
// Then delete the Configuration
161+
if err := clients.ServingClient.Configs.Delete(egCtx, names.Config, metav1.DeleteOptions{}); err != nil {
162+
return fmt.Errorf("failed to delete config: %w", err)
163+
}
164+
return nil
149165
})
150166

151167
if err := g.Wait(); err != nil {

0 commit comments

Comments
 (0)