From 001fc71bb49648e39afde2d1d7d392d59180c0d7 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 12 Nov 2025 23:53:17 +0100 Subject: [PATCH] outlet/kafka: fix race in tests This was introduced in the fix introduced in 7f5950f89cc0. --- outlet/kafka/root_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/outlet/kafka/root_test.go b/outlet/kafka/root_test.go index 2f82519c..69eb4932 100644 --- a/outlet/kafka/root_test.go +++ b/outlet/kafka/root_test.go @@ -5,6 +5,7 @@ package kafka import ( "context" + "sync/atomic" "testing" "time" @@ -17,7 +18,7 @@ func TestMock(t *testing.T) { got := []string{} expected := []string{"hello1", "hello2", "hello3"} gotAll := make(chan bool) - shutdownCalled := false + var shutdownCalled atomic.Bool callback := func(_ context.Context, message []byte) error { got = append(got, string(message)) if len(got) == len(expected) { @@ -27,7 +28,7 @@ func TestMock(t *testing.T) { } c.StartWorkers( func(int, chan<- ScaleRequest) (ReceiveFunc, ShutdownFunc) { - return callback, func() { shutdownCalled = true } + return callback, func() { shutdownCalled.Store(true) } }, ) @@ -47,7 +48,7 @@ func TestMock(t *testing.T) { c.Stop() time.Sleep(10 * time.Millisecond) - if !shutdownCalled { + if !shutdownCalled.Load() { t.Error("Stop() should have triggered shutdown function") } }