package coalesce import ( "context" "errors" "sync" "testing" ) func TestSignalCoalescesConcurrentNotifications(t *testing.T) { signal := NewSignal() var wg sync.WaitGroup for range 100 { wg.Add(1) go func() { defer wg.Done() signal.Notify() }() } wg.Wait() if err := signal.Wait(context.Background()); err != nil { t.Fatalf("Wait(): %v", err) } ctx, cancel := context.WithCancel(context.Background()) cancel() if err := signal.Wait(ctx); !errors.Is(err, context.Canceled) { t.Fatalf("second Wait() error = %v, want context.Canceled", err) } }