cronjob: shut down integration test quickly again

6f2cd1b5bd 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).
This commit is contained in:
Patrick Ohly 2023-03-08 17:26:47 +01:00
parent 0e9ad242bd
commit be82872eff

View File

@ -152,6 +152,10 @@ func TestCronJobLaunchesPodAndCleansUp(t *testing.T) {
closeFn, cjc, jc, informerSet, clientSet := setup(ctx, t) closeFn, cjc, jc, informerSet, clientSet := setup(ctx, t)
defer closeFn() defer closeFn()
// When shutting down, cancel must be called before closeFn.
// We simply call it multiple times.
defer cancel()
cronJobName := "foo" cronJobName := "foo"
namespaceName := "simple-cronjob-test" namespaceName := "simple-cronjob-test"