Skip to content

Commit ab51778

Browse files
authored
chore(test): actually wait for the os exit signal function to be called before asserting (#2303)
* chore(test): actually wait for the os exit signal function to be called before asserting * chore: some small reorg
1 parent 83bd80c commit ab51778

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cmd/installer/cli/signal_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func Test_signalHandler_Signal(t *testing.T) {
3131
if sig != nil {
3232
cleanupSignal = sig
3333
}
34-
wg.Done()
3534
}
3635

3736
// Save original os.Exit and restore after test
@@ -41,8 +40,8 @@ func Test_signalHandler_Signal(t *testing.T) {
4140
exitCode := int32(0)
4241
osExit = func(code int) {
4342
atomic.StoreInt32(&exitCode, int32(code))
44-
// Instead of exiting, just cancel the context
45-
cancel()
43+
// Resume the waitgroup to allow the test to complete
44+
wg.Done()
4645
}
4746

4847
// Set up the signal handler
@@ -76,6 +75,8 @@ func Test_signalHandler_Signal(t *testing.T) {
7675

7776
// Verify cleanup was called with the expected error
7877
assert.True(t, cleanupCalled, "Cleanup function should have been called")
78+
// Check that the context was cancelled
79+
assert.Equal(t, context.Canceled, ctx.Err())
7980
assert.Equal(t, syscall.SIGINT, cleanupSignal, "Cleanup should be called with SIGINT")
8081
assert.Equal(t, int32(1), atomic.LoadInt32(&exitCode), "Exit code should be 1")
8182
}

0 commit comments

Comments
 (0)