Skip to content

Commit f7fd0b8

Browse files
committed
Fix flaky TestDestroyPodInflight test
This fix addresses the root cause of test flakiness by ensuring traffic doesn't route through the activator during the graceful shutdown test. The flakiness occurred when requests routed through the activator (particularly with Kourier): deleting the Configuration triggered Revision deletion, causing the activator's revision lookup to fail for in-flight requests with 'revision not found' errors. The fix sets minScale=1 and target-burst-capacity=0 to: 1. Keep the revision active (prevents scale-to-zero) 2. Route traffic directly to the pod (bypasses the activator) This ensures the test properly validates graceful shutdown behavior regardless of resource deletion order, which was the original intent.
1 parent cf48bab commit f7fd0b8

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

test/e2e/destroypod_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/apimachinery/pkg/util/wait"
3737
pkgTest "knative.dev/pkg/test"
3838
"knative.dev/pkg/test/spoof"
39+
"knative.dev/serving/pkg/apis/autoscaling"
3940
"knative.dev/serving/pkg/apis/serving"
4041
v1 "knative.dev/serving/pkg/apis/serving/v1"
4142
rtesting "knative.dev/serving/pkg/testing/v1"
@@ -63,7 +64,20 @@ func TestDestroyPodInflight(t *testing.T) {
6364
test.EnsureTearDown(t, clients, &names)
6465

6566
t.Log("Creating a new Route and Configuration")
66-
if _, err := v1test.CreateConfiguration(t, clients, names, rtesting.WithConfigRevisionTimeoutSeconds(revisionTimeoutSeconds)); err != nil {
67+
// Set minScale=1 and target-burst-capacity=0 to ensure:
68+
// 1. The revision stays active (doesn't scale to zero)
69+
// 2. Traffic goes directly to the revision, bypassing the activator
70+
// This prevents "revision not found" errors when deleting the configuration
71+
// while in-flight requests are being handled by the activator.
72+
if _, err := v1test.CreateConfiguration(t, clients, names,
73+
rtesting.WithConfigRevisionTimeoutSeconds(revisionTimeoutSeconds),
74+
func(cfg *v1.Configuration) {
75+
if cfg.Spec.Template.Annotations == nil {
76+
cfg.Spec.Template.Annotations = make(map[string]string)
77+
}
78+
cfg.Spec.Template.Annotations[autoscaling.MinScaleAnnotationKey] = "1"
79+
cfg.Spec.Template.Annotations[autoscaling.TargetBurstCapacityKey] = "0"
80+
}); err != nil {
6781
t.Fatal("Failed to create Configuration:", err)
6882
}
6983
if _, err := v1test.CreateRoute(t, clients, names); err != nil {
@@ -144,8 +158,14 @@ func TestDestroyPodInflight(t *testing.T) {
144158
// Give the request a bit of time to be established and reach the pod.
145159
time.Sleep(timeoutRequestDuration / 2)
146160

147-
t.Log("Destroying the configuration (also destroys the pods)")
148-
return clients.ServingClient.Configs.Delete(egCtx, names.Config, metav1.DeleteOptions{})
161+
t.Log("Destroying the configuration and route (also destroys the pods)")
162+
if err := clients.ServingClient.Configs.Delete(egCtx, names.Config, metav1.DeleteOptions{}); err != nil {
163+
return fmt.Errorf("failed to delete config: %w", err)
164+
}
165+
if err := clients.ServingClient.Routes.Delete(egCtx, names.Route, metav1.DeleteOptions{}); err != nil {
166+
return fmt.Errorf("failed to delete route: %w", err)
167+
}
168+
return nil
149169
})
150170

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

0 commit comments

Comments
 (0)