test(evt): guard concurrent listener writes in blocking resolver test

signals dispatches each listener in its own goroutine and the denylist/
allowlist groups refresh concurrently, so the test's accumulator map needs
a mutex. Surfaced by go test -race.
This commit is contained in:
Dimitri Herzog
2026-06-05 22:29:03 +02:00
parent a3a6e7a104
commit 21de3077ec
+12 -1
View File
@@ -2,6 +2,7 @@ package resolver
import (
"context"
"sync"
"time"
"github.com/0xERR0R/blocky/config"
@@ -103,9 +104,14 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
})
When("List is refreshed", func() {
It("event should be fired", func() {
// Groups refresh concurrently and signals dispatches each listener in its
// own goroutine, so guard the accumulator against concurrent writes/reads.
var mu sync.Mutex
groupCnt := make(map[string]int)
bus := NewBus()
Subscribe(bus, "test:blocking-cache-group", func(_ context.Context, e BlockingCacheGroupChangedEvent) {
mu.Lock()
defer mu.Unlock()
groupCnt[e.GroupName] = e.Count
})
@@ -114,7 +120,12 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
sut, err = NewBlockingResolver(ctx, sutConfig, systemResolverBootstrap, bus)
Expect(err).Should(Succeed())
Eventually(groupCnt, "1s").Should(HaveLen(2))
Eventually(func() int {
mu.Lock()
defer mu.Unlock()
return len(groupCnt)
}, "1s").Should(Equal(2))
})
})
})