e2e: stop controller if context cancelled

This commit is contained in:
Antonio Ojea 2024-10-27 14:21:14 +00:00
parent e15d5b9da9
commit ad0bc4857b

View File

@ -355,9 +355,10 @@ func (j *TestJig) WaitForEndpointOnNode(ctx context.Context, nodeName string) er
// waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
//Wait for endpoints to be created, this may take longer time if service backing pods are taking longer time to run
endpointSelector := fields.OneTermEqualSelector("metadata.name", j.Name)
stopCh := make(chan struct{})
endpointAvailable := false
endpointSliceAvailable := false
@ -393,11 +394,8 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
},
},
)
defer func() {
close(stopCh)
}()
go controller.Run(stopCh)
go controller.Run(ctx.Done())
var esController cache.Controller
_, esController = cache.NewInformer(
@ -438,9 +436,9 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
},
)
go esController.Run(stopCh)
go esController.Run(ctx.Done())
err := wait.PollUntilContextTimeout(ctx, 1*time.Second, timeout, false, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextCancel(ctx, 1*time.Second, false, func(ctx context.Context) (bool, error) {
return endpointAvailable && endpointSliceAvailable, nil
})
if err != nil {