Skip to content

Commit 3caa40c

Browse files
authored
test(e2e): remove fixed-sleep flakiness across e2e specs (#427)
1 parent d07c436 commit 3caa40c

31 files changed

Lines changed: 657 additions & 723 deletions

test/e2e/crds/v1alpha1/backendtrafficpolicy.go

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package v1alpha1
2020
import (
2121
"context"
2222
"fmt"
23-
"time"
2423

2524
. "github.com/onsi/ginkgo/v2"
2625
. "github.com/onsi/gomega"
@@ -63,17 +62,14 @@ spec:
6362
By("create GatewayProxy")
6463
err = s.CreateResourceFromString(s.GetGatewayProxySpec())
6564
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
66-
time.Sleep(5 * time.Second)
6765

6866
By("create GatewayClass")
6967
err = s.CreateResourceFromString(s.GetGatewayClassYaml())
7068
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
71-
time.Sleep(5 * time.Second)
7269

7370
By("create Gateway")
7471
err = s.CreateResourceFromString(s.GetGatewayYaml())
7572
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
76-
time.Sleep(5 * time.Second)
7773

7874
By("create HTTPRoute")
7975
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(defaultHTTPRoute, s.Namespace(), s.Namespace()))
@@ -232,28 +228,28 @@ spec:
232228
scaffold.WithExpectedStatus(200),
233229
},
234230
})
235-
time.Sleep(2 * time.Second)
236-
237-
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
238-
Expect(err).ToNot(HaveOccurred(), "listing upstreams")
239-
Expect(ups).NotTo(BeEmpty(), "upstreams should not be empty")
240-
241-
var target *adctypes.Upstream
242-
for _, u := range ups {
243-
if u.Checks != nil {
244-
target = u
245-
break
231+
Eventually(func(g Gomega) {
232+
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
233+
g.Expect(err).ToNot(HaveOccurred(), "listing upstreams")
234+
g.Expect(ups).NotTo(BeEmpty(), "upstreams should not be empty")
235+
236+
var target *adctypes.Upstream
237+
for _, u := range ups {
238+
if u.Checks != nil {
239+
target = u
240+
break
241+
}
246242
}
247-
}
248-
Expect(target).NotTo(BeNil(), "upstream with health check should exist")
249-
Expect(target.Checks.Active).NotTo(BeNil(), "active health check should be configured")
250-
Expect(target.Checks.Active.HTTPPath).To(Equal("/get"), "active health check http path")
251-
Expect(target.Checks.Active.Healthy.Interval).To(Equal(1), "active healthy interval")
252-
Expect(target.Checks.Active.Healthy.HTTPStatuses).To(Equal([]int{200}), "active healthy http codes")
253-
Expect(target.Checks.Active.Unhealthy.Interval).To(Equal(1), "active unhealthy interval")
254-
Expect(target.Checks.Active.Unhealthy.HTTPFailures).To(Equal(2), "active unhealthy http failures")
255-
Expect(target.Checks.Active.Unhealthy.HTTPStatuses).To(Equal([]int{500}), "active unhealthy http codes")
256-
Expect(target.Checks.Passive).To(BeNil(), "passive health check should not be configured")
243+
g.Expect(target).NotTo(BeNil(), "upstream with health check should exist")
244+
g.Expect(target.Checks.Active).NotTo(BeNil(), "active health check should be configured")
245+
g.Expect(target.Checks.Active.HTTPPath).To(Equal("/get"), "active health check http path")
246+
g.Expect(target.Checks.Active.Healthy.Interval).To(Equal(1), "active healthy interval")
247+
g.Expect(target.Checks.Active.Healthy.HTTPStatuses).To(Equal([]int{200}), "active healthy http codes")
248+
g.Expect(target.Checks.Active.Unhealthy.Interval).To(Equal(1), "active unhealthy interval")
249+
g.Expect(target.Checks.Active.Unhealthy.HTTPFailures).To(Equal(2), "active unhealthy http failures")
250+
g.Expect(target.Checks.Active.Unhealthy.HTTPStatuses).To(Equal([]int{500}), "active unhealthy http codes")
251+
g.Expect(target.Checks.Passive).To(BeNil(), "passive health check should not be configured")
252+
}).WithTimeout(scaffold.DefaultTimeout).ProbeEvery(scaffold.DefaultInterval).Should(Succeed())
257253
})
258254

259255
It("should configure active and passive health checks on upstream", func() {
@@ -268,31 +264,31 @@ spec:
268264
scaffold.WithExpectedStatus(200),
269265
},
270266
})
271-
time.Sleep(2 * time.Second)
272-
273-
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
274-
Expect(err).ToNot(HaveOccurred(), "listing upstreams")
275-
Expect(ups).NotTo(BeEmpty(), "upstreams should not be empty")
276-
277-
var target *adctypes.Upstream
278-
for _, u := range ups {
279-
if u.Checks != nil && u.Checks.Passive != nil {
280-
target = u
281-
break
267+
Eventually(func(g Gomega) {
268+
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
269+
g.Expect(err).ToNot(HaveOccurred(), "listing upstreams")
270+
g.Expect(ups).NotTo(BeEmpty(), "upstreams should not be empty")
271+
272+
var target *adctypes.Upstream
273+
for _, u := range ups {
274+
if u.Checks != nil && u.Checks.Passive != nil {
275+
target = u
276+
break
277+
}
282278
}
283-
}
284-
Expect(target).NotTo(BeNil(), "upstream with active and passive health check should exist")
285-
286-
// Verify active health check
287-
Expect(target.Checks.Active).NotTo(BeNil(), "active health check should be configured")
288-
Expect(target.Checks.Active.HTTPPath).To(Equal("/get"), "active health check http path")
289-
Expect(target.Checks.Active.Healthy.HTTPStatuses).To(Equal([]int{200}), "active healthy http codes")
290-
Expect(target.Checks.Active.Unhealthy.HTTPFailures).To(Equal(2), "active unhealthy http failures")
291-
292-
// Verify passive health check
293-
Expect(target.Checks.Passive.Healthy.HTTPStatuses).To(Equal([]int{200}), "passive healthy http codes")
294-
Expect(target.Checks.Passive.Unhealthy.HTTPStatuses).To(Equal([]int{502, 503}), "passive unhealthy http codes")
295-
Expect(target.Checks.Passive.Unhealthy.HTTPFailures).To(Equal(3), "passive unhealthy http failures")
279+
g.Expect(target).NotTo(BeNil(), "upstream with active and passive health check should exist")
280+
281+
// Verify active health check
282+
g.Expect(target.Checks.Active).NotTo(BeNil(), "active health check should be configured")
283+
g.Expect(target.Checks.Active.HTTPPath).To(Equal("/get"), "active health check http path")
284+
g.Expect(target.Checks.Active.Healthy.HTTPStatuses).To(Equal([]int{200}), "active healthy http codes")
285+
g.Expect(target.Checks.Active.Unhealthy.HTTPFailures).To(Equal(2), "active unhealthy http failures")
286+
287+
// Verify passive health check
288+
g.Expect(target.Checks.Passive.Healthy.HTTPStatuses).To(Equal([]int{200}), "passive healthy http codes")
289+
g.Expect(target.Checks.Passive.Unhealthy.HTTPStatuses).To(Equal([]int{502, 503}), "passive unhealthy http codes")
290+
g.Expect(target.Checks.Passive.Unhealthy.HTTPFailures).To(Equal(3), "passive unhealthy http failures")
291+
}).WithTimeout(scaffold.DefaultTimeout).ProbeEvery(scaffold.DefaultInterval).Should(Succeed())
296292
})
297293

298294
It("should remove health check when policy is deleted", func() {
@@ -307,32 +303,33 @@ spec:
307303
scaffold.WithExpectedStatus(200),
308304
},
309305
})
310-
time.Sleep(2 * time.Second)
311-
312306
// Verify health check is present on the target upstream
313-
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
314-
Expect(err).ToNot(HaveOccurred())
315-
hasHealthCheck := false
316-
for _, u := range ups {
317-
if u.Checks != nil {
318-
hasHealthCheck = true
319-
break
307+
Eventually(func(g Gomega) {
308+
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
309+
g.Expect(err).ToNot(HaveOccurred())
310+
hasHealthCheck := false
311+
for _, u := range ups {
312+
if u.Checks != nil {
313+
hasHealthCheck = true
314+
break
315+
}
320316
}
321-
}
322-
Expect(hasHealthCheck).To(BeTrue(), "upstream should have health check before policy deletion")
317+
g.Expect(hasHealthCheck).To(BeTrue(), "upstream should have health check before policy deletion")
318+
}).WithTimeout(scaffold.DefaultTimeout).ProbeEvery(scaffold.DefaultInterval).Should(Succeed())
323319

324320
// Delete the policy
325321
err = s.DeleteResourceFromString(policyWithActiveHealthCheck)
326322
Expect(err).NotTo(HaveOccurred(), "deleting BackendTrafficPolicy")
327-
time.Sleep(3 * time.Second)
328323

329324
// Verify health check is removed from the target upstream
330-
ups, err = s.DefaultDataplaneResource().Upstream().List(context.Background())
331-
Expect(err).ToNot(HaveOccurred())
332-
Expect(ups).NotTo(BeEmpty(), "upstreams should still exist after policy deletion")
333-
for _, u := range ups {
334-
Expect(u.Checks).To(BeNil(), "upstream should not have health check after policy deletion")
335-
}
325+
Eventually(func(g Gomega) {
326+
ups, err := s.DefaultDataplaneResource().Upstream().List(context.Background())
327+
g.Expect(err).ToNot(HaveOccurred())
328+
g.Expect(ups).NotTo(BeEmpty(), "upstreams should still exist after policy deletion")
329+
for _, u := range ups {
330+
g.Expect(u.Checks).To(BeNil(), "upstream should not have health check after policy deletion")
331+
}
332+
}).WithTimeout(scaffold.DefaultTimeout).ProbeEvery(scaffold.DefaultInterval).Should(Succeed())
336333
})
337334
})
338335
})
@@ -379,7 +376,6 @@ spec:
379376
By("create GatewayProxy")
380377
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
381378
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
382-
time.Sleep(5 * time.Second)
383379

384380
By("create IngressClass with GatewayProxy reference")
385381
err = s.CreateResourceFromString(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), s.Namespace()))

test/e2e/crds/v1alpha1/consumer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,14 @@ spec:
8080
By("create GatewayProxy")
8181
err = s.CreateResourceFromString(s.GetGatewayProxySpec())
8282
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
83-
time.Sleep(time.Second)
8483

8584
By("create GatewayClass")
8685
err = s.CreateResourceFromString(s.GetGatewayClassYaml())
8786
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
88-
time.Sleep(time.Second)
8987

9088
By("create Gateway")
9189
err = s.CreateResourceFromString(s.GetGatewayYaml())
9290
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
93-
time.Sleep(time.Second)
9491

9592
By("create HTTPRoute")
9693
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(defaultHTTPRoute, s.Namespace()))

test/e2e/crds/v1alpha1/gatewayproxy.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,14 @@ spec:
117117
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxySpec, framework.ProviderType, s.AdminKey()))
118118
}
119119
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
120-
time.Sleep(5 * time.Second)
121120

122121
By("create GatewayClass")
123122
err = s.CreateResourceFromString(s.GetGatewayClassYaml())
124123
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
125-
time.Sleep(5 * time.Second)
126124

127125
By("create Gateway")
128126
err = s.CreateResourceFromString(s.GetGatewayYaml())
129127
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
130-
time.Sleep(5 * time.Second)
131128

132129
By("create HTTPRoute")
133130
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(httpRouteSpec, gatewayName))

test/e2e/crds/v2/basic.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ var _ = Describe("APISIX Standalone Basic Tests", Label("apisix.apache.org", "v2
6767
By("create GatewayProxy")
6868
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
6969
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
70-
time.Sleep(5 * time.Second)
7170

7271
By("create IngressClass")
7372
err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "")
7473
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
75-
time.Sleep(5 * time.Second)
7674

7775
const apisixRouteSpec = `
7876
apiVersion: apisix.apache.org/v2

test/e2e/crds/v2/consumer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ var _ = Describe("Test ApisixConsumer", Label("apisix.apache.org", "v2", "apisix
7272
By("create GatewayProxy")
7373
err := s.CreateResourceFromString(s.GetGatewayProxySpec())
7474
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
75-
time.Sleep(5 * time.Second)
7675

7776
By("create IngressClass")
7877
err = s.CreateResourceFromStringWithNamespace(s.GetIngressClassYaml(), "")
7978
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
80-
time.Sleep(5 * time.Second)
8179
})
8280

8381
Context("Test KeyAuth", func() {

0 commit comments

Comments
 (0)