@@ -20,7 +20,6 @@ package v1alpha1
2020import (
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 ()))
0 commit comments