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:
parent
dee6149c06
commit
6cec9aa8ac
1 changed files with 7 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue