Watch
1
0
Fork
You've already forked RedFlag
0

test: atomic counter in notifier countingSink

Dispatch fires sinks in goroutines; the plain-int counter tripped
go test -race. CI red since the notification bell landed.
This commit is contained in:
Fimeg 2026-06-11 20:27:28 -04:00
commit 6cec9aa8ac

View file

@ -2,6 +2,7 @@ package notifier
import (
"context"
"sync/atomic"
"testing"
"time"
)
@ -86,8 +87,8 @@ func TestDispatcherDedup(t *testing.T) {
// Let goroutines settle.
time.Sleep(20 * time.Millisecond)
if cs.count != 1 {
t.Errorf("expected exactly 1 delivery (dedup suppressed the rest), got %d", cs.count)
if cs.count.Load() != 1 {
t.Errorf("expected exactly 1 delivery (dedup suppressed the rest), got %d", cs.count.Load())
}
}
@ -106,17 +107,17 @@ func TestDispatcherNoDedupDifferentFP(t *testing.T) {
time.Sleep(20 * time.Millisecond)
if cs.count != 2 {
t.Errorf("expected 2 deliveries for different fingerprints, got %d", cs.count)
if cs.count.Load() != 2 {
t.Errorf("expected 2 deliveries for different fingerprints, got %d", cs.count.Load())
}
}
type countingSink struct {
count int
count atomic.Int64
}
func (s *countingSink) ID() string { return "test" }
func (s *countingSink) Send(_ context.Context, _ NotifyEvent) error {
s.count++
s.count.Add(1)
return nil
}