Skip to content

Commit cb8a7ca

Browse files
authored
test(e2e): add graceful shutdown test for long-running requests (#7350)
Signed-off-by: Lin Moskovitch <[email protected]>
1 parent 282c916 commit cb8a7ca

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

test/e2e/tests/backend_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var BackendUpgradeTest = suite.ConformanceTest{
6969

7070
tlog.Logf(t, "Starting load generation")
7171
// Run load async and continue to restart deployment
72-
go runLoadAndWait(t, &suite.TimeoutConfig, loadSuccess, aborter, reqURL.String())
72+
go runLoadAndWait(t, &suite.TimeoutConfig, loadSuccess, aborter, reqURL.String(), 0)
7373

7474
tlog.Logf(t, "Restarting deployment")
7575
err = restartDeploymentAndWaitForNewPods(t, &suite.TimeoutConfig, suite.Client, dp)

test/e2e/tests/envoy_shutdown.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ var EnvoyShutdownTest = suite.ConformanceTest{
3939
Description: "Deleting envoy pod should not lead to failures",
4040
Manifests: []string{"testdata/envoy-shutdown.yaml"},
4141
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
42-
t.Run("All requests must succeed", func(t *testing.T) {
42+
t.Run("All requests (regular + delayed) must succeed during rollout", func(t *testing.T) {
4343
ns := "gateway-upgrade-infra"
4444
name := "ha-gateway"
4545
routeNN := types.NamespacedName{Name: "http-envoy-shutdown", Namespace: ns}
4646
gwNN := types.NamespacedName{Name: name, Namespace: ns}
4747
gwAddr := kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &gwapiv1.HTTPRoute{}, false, routeNN)
48-
reqURL := url.URL{Scheme: "http", Host: http.CalculateHost(t, gwAddr, "http"), Path: "/envoy-shutdown"}
48+
baseURL := url.URL{Scheme: "http", Host: http.CalculateHost(t, gwAddr, "http"), Path: "/envoy-shutdown"}
4949
epNN := types.NamespacedName{Name: "upgrade-config", Namespace: "envoy-gateway-system"}
5050
dp, err := getDeploymentForGateway(ns, name, suite.Client)
5151
if err != nil {
@@ -66,29 +66,39 @@ var EnvoyShutdownTest = suite.ConformanceTest{
6666
}
6767
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
6868

69-
// can be used to abort the test after deployment restart is complete or failed
7069
aborter := periodic.NewAborter()
71-
// will contain indication on success or failure of load test
72-
loadSuccess := make(chan bool)
70+
regDone := make(chan bool)
71+
delayedDone := make(chan bool)
7372

74-
t.Log("Starting load generation")
75-
// Run load async and continue to restart deployment
76-
go runLoadAndWait(t, &suite.TimeoutConfig, loadSuccess, aborter, reqURL.String())
73+
regURL := baseURL.String()
74+
delayedURL := func() string {
75+
u := baseURL
76+
q := u.Query()
77+
q.Set("delay", "3s")
78+
u.RawQuery = q.Encode()
79+
return u.String()
80+
}()
81+
82+
t.Logf("Starting regular load to %s", regURL)
83+
go runLoadAndWait(t, &suite.TimeoutConfig, regDone, aborter, regURL, 0)
84+
85+
t.Logf("Starting delayed load to %s", delayedURL)
86+
go runLoadAndWait(t, &suite.TimeoutConfig, delayedDone, aborter, delayedURL, 10*time.Second)
7787

7888
t.Log("Rolling out proxy deployment")
7989
err = restartProxyAndWaitForRollout(t, &suite.TimeoutConfig, suite.Client, epNN, dp)
8090

8191
t.Log("Stopping load generation and collecting results")
82-
aborter.Abort(false) // abort the load either way
92+
aborter.Abort(false)
8393

8494
if err != nil {
8595
t.Errorf("Failed to rollout proxy deployment: %v", err)
8696
}
87-
88-
// Wait for the goroutine to finish
89-
result := <-loadSuccess
90-
if !result {
91-
t.Errorf("Load test failed")
97+
if ok := <-regDone; !ok {
98+
t.Errorf("Regular load failed during rollout")
99+
}
100+
if ok := <-delayedDone; !ok {
101+
t.Errorf("Delayed load failed during rollout")
92102
}
93103
})
94104
},

test/e2e/tests/utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func AlmostEquals(actual, expect, offset int) bool {
251251
// runs a load test with options described in opts
252252
// the done channel is used to notify caller of execution result
253253
// the execution may end due to an external abort or timeout
254-
func runLoadAndWait(t *testing.T, timeoutConfig *config.TimeoutConfig, done chan bool, aborter *periodic.Aborter, reqURL string) {
254+
func runLoadAndWait(t *testing.T, timeoutConfig *config.TimeoutConfig, done chan bool, aborter *periodic.Aborter, reqURL string, reqTimeout time.Duration) {
255255
qpsVal := os.Getenv("E2E_BACKEND_UPGRADE_QPS")
256256
qps := 5000
257257
if qpsVal != "" {
@@ -277,6 +277,10 @@ func runLoadAndWait(t *testing.T, timeoutConfig *config.TimeoutConfig, done chan
277277
},
278278
}
279279

280+
if reqTimeout > 0 {
281+
opts.HTTPReqTimeOut = reqTimeout
282+
}
283+
280284
res, err := fhttp.RunHTTPTest(&opts)
281285
if err != nil {
282286
done <- false

0 commit comments

Comments
 (0)