Skip to content

Commit 85ae17d

Browse files
committed
chore: address race condition in tests
1 parent ebc4543 commit 85ae17d

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
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os"
66
"sync"
7+
"sync/atomic"
78
"syscall"
89
"testing"
910
"time"
@@ -37,9 +38,9 @@ func Test_signalHandler_Signal(t *testing.T) {
3738
originalOsExit := osExit
3839
defer func() { osExit = originalOsExit }()
3940

40-
exitCode := 0
41+
exitCode := int32(0)
4142
osExit = func(code int) {
42-
exitCode = code
43+
atomic.StoreInt32(&exitCode, int32(code))
4344
// Instead of exiting, just cancel the context
4445
cancel()
4546
}
@@ -76,7 +77,7 @@ func Test_signalHandler_Signal(t *testing.T) {
7677
// Verify cleanup was called with the expected error
7778
assert.True(t, cleanupCalled, "Cleanup function should have been called")
7879
assert.Equal(t, syscall.SIGINT, cleanupSignal, "Cleanup should be called with SIGINT")
79-
assert.Equal(t, 1, exitCode, "Exit code should be 1")
80+
assert.Equal(t, int32(1), atomic.LoadInt32(&exitCode), "Exit code should be 1")
8081
}
8182

8283
func Test_signalHandler_ContextDone(t *testing.T) {

0 commit comments

Comments
 (0)