diff --git a/internal/shared/lifecycle/lifecycle_test.go b/internal/shared/lifecycle/lifecycle_test.go index 311bb7a..b232a99 100644 --- a/internal/shared/lifecycle/lifecycle_test.go +++ b/internal/shared/lifecycle/lifecycle_test.go @@ -2,25 +2,27 @@ package lifecycle import ( "os" + "sync" "syscall" "testing" - "time" "github.com/stretchr/testify/assert" ) func Test_GivenTerminationSignal_WhenListenForShutdown_ThenCallsTheFunctionPassed(t *testing.T) { shutdownSignal := make(chan os.Signal, 1) - + var wg sync.WaitGroup shutdownFuncCalled := false shutdownFunc := func() { + defer wg.Done() shutdownFuncCalled = true } + wg.Add(1) go ListenForApplicationShutDown(shutdownFunc, shutdownSignal) shutdownSignal <- syscall.SIGTERM + wg.Wait() - time.Sleep(time.Second) assert.True(t, shutdownFuncCalled) }