@@ -24,6 +24,7 @@ import (
24
24
"reflect"
25
25
"strconv"
26
26
"strings"
27
+ "sync"
27
28
"testing"
28
29
"time"
29
30
@@ -268,12 +269,14 @@ func MeshNamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig conf
268
269
}
269
270
270
271
// GatewayAndHTTPRoutesMustBeAccepted waits until:
271
- // 1. The specified Gateway has an IP address assigned to it.
272
- // 2. The route has a ParentRef referring to the Gateway.
273
- // 3. All the gateway's listeners have the ListenerConditionResolvedRefs set to true.
272
+ // 1. The specified Gateway has an IP address assigned to it.
273
+ // 2. The route has a ParentRef referring to the Gateway.
274
+ // 3. All the gateway's listeners have the following conditions set to true:
275
+ // - ListenerConditionResolvedRefs
276
+ // - ListenerConditionAccepted
277
+ // - ListenerConditionProgrammed
274
278
//
275
- // The test will fail if these conditions are not met before the
276
- // timeouts.
279
+ // The test will fail if these conditions are not met before the timeouts.
277
280
func GatewayAndHTTPRoutesMustBeAccepted (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , controllerName string , gw GatewayRef , routeNNs ... types.NamespacedName ) string {
278
281
t .Helper ()
279
282
@@ -310,13 +313,24 @@ func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCo
310
313
HTTPRouteMustHaveParents (t , c , timeoutConfig , routeNN , parents , namespaceRequired )
311
314
}
312
315
313
- resolvedRefsCondition := metav1.Condition {
314
- Type : string (v1beta1 .ListenerConditionResolvedRefs ),
315
- Status : metav1 .ConditionTrue ,
316
- Reason : "" , // any reason
316
+ requiredListenerConditions := []metav1.Condition {
317
+ {
318
+ Type : string (v1beta1 .ListenerConditionResolvedRefs ),
319
+ Status : metav1 .ConditionTrue ,
320
+ Reason : "" , // any reason
321
+ },
322
+ {
323
+ Type : string (v1beta1 .ListenerConditionAccepted ),
324
+ Status : metav1 .ConditionTrue ,
325
+ Reason : "" , // any reason
326
+ },
327
+ {
328
+ Type : string (v1beta1 .ListenerConditionProgrammed ),
329
+ Status : metav1 .ConditionTrue ,
330
+ Reason : "" , // any reason
331
+ },
317
332
}
318
-
319
- GatewayListenersMustHaveCondition (t , c , timeoutConfig , gw .NamespacedName , resolvedRefsCondition )
333
+ GatewayListenersMustHaveConditions (t , c , timeoutConfig , gw .NamespacedName , requiredListenerConditions )
320
334
321
335
return gwAddr
322
336
}
@@ -356,27 +370,38 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
356
370
return net .JoinHostPort (ipAddr , port ), waitErr
357
371
}
358
372
359
- // GatewayListenersMustHaveCondition checks if every listener of the specified gateway has a
360
- // certain condition .
361
- func GatewayListenersMustHaveCondition (t * testing.T , client client.Client , timeoutConfig config.TimeoutConfig , gwName types.NamespacedName , condition metav1.Condition ) {
373
+ // GatewayListenersMustHaveConditions checks if every listener of the specified gateway has all
374
+ // the specified conditions .
375
+ func GatewayListenersMustHaveConditions (t * testing.T , client client.Client , timeoutConfig config.TimeoutConfig , gwName types.NamespacedName , conditions [] metav1.Condition ) {
362
376
t .Helper ()
363
377
364
- waitErr := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , timeoutConfig .GatewayListenersMustHaveCondition , true , func (ctx context.Context ) (bool , error ) {
365
- var gw v1beta1.Gateway
366
- if err := client .Get (ctx , gwName , & gw ); err != nil {
367
- return false , fmt .Errorf ("error fetching Gateway: %w" , err )
368
- }
378
+ var wg sync.WaitGroup
379
+ wg .Add (len (conditions ))
369
380
370
- for _ , listener := range gw .Status .Listeners {
371
- if ! findConditionInList (t , listener .Conditions , condition .Type , string (condition .Status ), condition .Reason ) {
372
- return false , nil
373
- }
374
- }
381
+ for _ , condition := range conditions {
382
+ go func (condition metav1.Condition ) {
383
+ defer wg .Done ()
375
384
376
- return true , nil
377
- })
385
+ waitErr := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , timeoutConfig .GatewayListenersMustHaveCondition , true , func (ctx context.Context ) (bool , error ) {
386
+ var gw v1beta1.Gateway
387
+ if err := client .Get (ctx , gwName , & gw ); err != nil {
388
+ return false , fmt .Errorf ("error fetching Gateway: %w" , err )
389
+ }
390
+
391
+ for _ , listener := range gw .Status .Listeners {
392
+ if ! findConditionInList (t , listener .Conditions , condition .Type , string (condition .Status ), condition .Reason ) {
393
+ return false , nil
394
+ }
395
+ }
396
+
397
+ return true , nil
398
+ })
399
+
400
+ require .NoErrorf (t , waitErr , "error waiting for Gateway status to have a Condition matching expectations on all listeners" )
401
+ }(condition )
402
+ }
378
403
379
- require . NoErrorf ( t , waitErr , "error waiting for Gateway status to have a Condition matching expectations on all listeners" )
404
+ wg . Wait ( )
380
405
}
381
406
382
407
// GatewayMustHaveZeroRoutes validates that the gateway has zero routes attached. The status
0 commit comments