Skip to content

Commit 1148e5e

Browse files
authored
Merge pull request kubernetes#128363 from aojea/e2e_context_cancellation
e2e: stop controller if context cancelled
2 parents e15d5b9 + ad0bc48 commit 1148e5e

File tree

1 file changed

+5
-7
lines changed
  • test/e2e/framework/service

1 file changed

+5
-7
lines changed

test/e2e/framework/service/jig.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,10 @@ func (j *TestJig) WaitForEndpointOnNode(ctx context.Context, nodeName string) er
355355

356356
// waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
357357
func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Duration) error {
358+
ctx, cancel := context.WithTimeout(ctx, timeout)
359+
defer cancel()
358360
//Wait for endpoints to be created, this may take longer time if service backing pods are taking longer time to run
359361
endpointSelector := fields.OneTermEqualSelector("metadata.name", j.Name)
360-
stopCh := make(chan struct{})
361362
endpointAvailable := false
362363
endpointSliceAvailable := false
363364

@@ -393,11 +394,8 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
393394
},
394395
},
395396
)
396-
defer func() {
397-
close(stopCh)
398-
}()
399397

400-
go controller.Run(stopCh)
398+
go controller.Run(ctx.Done())
401399

402400
var esController cache.Controller
403401
_, esController = cache.NewInformer(
@@ -438,9 +436,9 @@ func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Dur
438436
},
439437
)
440438

441-
go esController.Run(stopCh)
439+
go esController.Run(ctx.Done())
442440

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) {
444442
return endpointAvailable && endpointSliceAvailable, nil
445443
})
446444
if err != nil {

0 commit comments

Comments
 (0)