@@ -355,9 +355,10 @@ func (j *TestJig) WaitForEndpointOnNode(ctx context.Context, nodeName string) er
355
355
356
356
// waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
357
357
func (j * TestJig ) waitForAvailableEndpoint (ctx context.Context , timeout time.Duration ) error {
358
+ ctx , cancel := context .WithTimeout (ctx , timeout )
359
+ defer cancel ()
358
360
//Wait for endpoints to be created, this may take longer time if service backing pods are taking longer time to run
359
361
endpointSelector := fields .OneTermEqualSelector ("metadata.name" , j .Name )
360
- stopCh := make (chan struct {})
361
362
endpointAvailable := false
362
363
endpointSliceAvailable := false
363
364
@@ -393,11 +394,8 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
393
394
},
394
395
},
395
396
)
396
- defer func () {
397
- close (stopCh )
398
- }()
399
397
400
- go controller .Run (stopCh )
398
+ go controller .Run (ctx . Done () )
401
399
402
400
var esController cache.Controller
403
401
_ , esController = cache .NewInformer (
@@ -438,9 +436,9 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
438
436
},
439
437
)
440
438
441
- go esController .Run (stopCh )
439
+ go esController .Run (ctx . Done () )
442
440
443
- err := wait .PollUntilContextTimeout (ctx , 1 * time .Second , timeout , false , func (ctx context.Context ) (bool , error ) {
441
+ err := wait .PollUntilContextCancel (ctx , 1 * time .Second , false , func (ctx context.Context ) (bool , error ) {
444
442
return endpointAvailable && endpointSliceAvailable , nil
445
443
})
446
444
if err != nil {
0 commit comments