package service import ( "context" "os" "testing" "time" ) func TestWaitForStopReturnsOnSignal(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() signals := make(chan os.Signal, 1) done := make(chan struct{}) go func() { WaitForStop(ctx, signals) close(done) }() signals <- os.Interrupt select { case <-done: case <-time.After(time.Second): t.Fatal("shutdown did not return after signal") } }