From be82872effe9f2f670524c5cb9adefa873231562 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 8 Mar 2023 17:26:47 +0100 Subject: [PATCH] cronjob: shut down integration test quickly again 6f2cd1b5bd76e336c08846281db1aacca1e7dd13 swapped the order of cancel() and closeFn() so that closeFn got called first when the test was done. This caused it to block while waiting for goroutines which themselves were waiting for the context cancellation. The test still shut down, it just took ~86s instead of ~30s. The fix is to register the cancel twice: once as soon as the context is created (to clean up in case of an unexpected panic) and once after closeFn (because then it'll get called first, as before). --- test/integration/cronjob/cronjob_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/integration/cronjob/cronjob_test.go b/test/integration/cronjob/cronjob_test.go index 2c149473a84..6cdbf2a42f4 100644 --- a/test/integration/cronjob/cronjob_test.go +++ b/test/integration/cronjob/cronjob_test.go @@ -152,6 +152,10 @@ func TestCronJobLaunchesPodAndCleansUp(t *testing.T) { closeFn, cjc, jc, informerSet, clientSet := setup(ctx, t) defer closeFn() + // When shutting down, cancel must be called before closeFn. + // We simply call it multiple times. + defer cancel() + cronJobName := "foo" namespaceName := "simple-cronjob-test"