From c54699e97aca0b76851c9847f406976a7f47ef50 Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Fri, 13 Nov 2020 09:28:06 +0800 Subject: [PATCH] Add check for exit - 10s for sync catalog since it needs more time --- subcommand/lifecycle-sidecar/command_test.go | 11 ++++++++++- subcommand/sync-catalog/command_test.go | 11 ++++++++++- subcommand/webhook-cert-manager/command_test.go | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/subcommand/lifecycle-sidecar/command_test.go b/subcommand/lifecycle-sidecar/command_test.go index df3b1b6122..d31e669bf8 100644 --- a/subcommand/lifecycle-sidecar/command_test.go +++ b/subcommand/lifecycle-sidecar/command_test.go @@ -44,7 +44,16 @@ func testRunSignalHandling(sig os.Signal) func(*testing.T) { exitChan := runCommandAsynchronously(&cmd, []string{ "-service-config", configFile, }) - defer stopCommand(t, &cmd, exitChan, sig) + cmd.sendSignal(sig) + + // Assert that it exits cleanly or timeout. + select { + case exitCode := <-exitChan: + require.Equal(t, 0, exitCode, ui.ErrorWriter.String()) + case <-time.After(time.Second * 1): + // Fail if the signal was not caught. + require.Fail(t, "timeout waiting for command to exit") + } } } diff --git a/subcommand/sync-catalog/command_test.go b/subcommand/sync-catalog/command_test.go index 6144d05e91..185e130ba8 100644 --- a/subcommand/sync-catalog/command_test.go +++ b/subcommand/sync-catalog/command_test.go @@ -108,7 +108,16 @@ func testSignalHandling(sig os.Signal) func(*testing.T) { exitChan := runCommandAsynchronously(&cmd, []string{ "-http-addr", testServer.HTTPAddr, }) - defer stopCommand(t, &cmd, exitChan, sig) + cmd.sendSignal(sig) + + // Assert that it exits cleanly or timeout. + select { + case exitCode := <-exitChan: + require.Equal(t, 0, exitCode, ui.ErrorWriter.String()) + case <-time.After(time.Second * 10): + // Fail if the signal was not caught. + require.Fail(t, "timeout waiting for command to exit") + } } } diff --git a/subcommand/webhook-cert-manager/command_test.go b/subcommand/webhook-cert-manager/command_test.go index 4bb963b758..f2f23bab25 100644 --- a/subcommand/webhook-cert-manager/command_test.go +++ b/subcommand/webhook-cert-manager/command_test.go @@ -83,7 +83,16 @@ func testSignalHandling(sig os.Signal) func(*testing.T) { exitCh := runCommandAsynchronously(&cmd, []string{ "-config-file", file.Name(), }) - defer stopCommand(t, &cmd, exitCh, sig) + cmd.sendSignal(sig) + + // Assert that it exits cleanly or timeout. + select { + case exitCode := <-exitCh: + require.Equal(t, 0, exitCode, ui.ErrorWriter.String()) + case <-time.After(time.Second * 1): + // Fail if the signal was not caught. + require.Fail(t, "timeout waiting for command to exit") + } } }