From 0e0b862bd7028ce2dcc463b58133de4b2a04ecb1 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Wed, 28 Jan 2026 11:52:08 +0200 Subject: [PATCH] silenced race detector errors per #7484 --- tools/cron/cron_test.go | 15 +++++++++++++-- tools/search/provider_test.go | 4 ++++ tools/subscriptions/client_test.go | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/cron/cron_test.go b/tools/cron/cron_test.go index 8b18dc1a..9b6dc33f 100644 --- a/tools/cron/cron_test.go +++ b/tools/cron/cron_test.go @@ -3,6 +3,7 @@ package cron import ( "encoding/json" "slices" + "sync" "testing" "time" ) @@ -253,6 +254,8 @@ func TestCronJobs(t *testing.T) { func TestCronStartStop(t *testing.T) { t.Parallel() + var mu sync.Mutex + test1 := 0 test2 := 0 @@ -261,15 +264,17 @@ func TestCronStartStop(t *testing.T) { c.SetInterval(250 * time.Millisecond) c.Add("test1", "* * * * *", func() { + mu.Lock() + defer mu.Unlock() test1++ }) c.Add("test2", "* * * * *", func() { + mu.Lock() + defer mu.Unlock() test2++ }) - expectedCalls := 2 - // call twice Start to check if the previous ticker will be reseted c.Start() c.Start() @@ -280,12 +285,16 @@ func TestCronStartStop(t *testing.T) { c.Stop() c.Stop() + expectedCalls := 2 + + mu.Lock() if test1 != expectedCalls { t.Fatalf("Expected %d test1, got %d", expectedCalls, test1) } if test2 != expectedCalls { t.Fatalf("Expected %d test2, got %d", expectedCalls, test2) } + mu.Unlock() // resume for 1 seconds c.Start() @@ -296,10 +305,12 @@ func TestCronStartStop(t *testing.T) { expectedCalls += 4 + mu.Lock() if test1 != expectedCalls { t.Fatalf("Expected %d test1, got %d", expectedCalls, test1) } if test2 != expectedCalls { t.Fatalf("Expected %d test2, got %d", expectedCalls, test2) } + mu.Unlock() } diff --git a/tools/search/provider_test.go b/tools/search/provider_test.go index 0a523983..fc73a4df 100644 --- a/tools/search/provider_test.go +++ b/tools/search/provider_test.go @@ -8,6 +8,7 @@ import ( "fmt" "strconv" "strings" + "sync" "testing" "time" @@ -741,6 +742,7 @@ type testTableStruct struct { type testDB struct { *dbx.DB + mu sync.Mutex CalledQueries []string } @@ -765,6 +767,8 @@ func createTestDB() (*testDB, error) { db.Insert("test", dbx.Params{"id": 1, "test1": 1, "test2": "test2.1"}).Execute() db.Insert("test", dbx.Params{"id": 2, "test1": 2, "test2": "test2.2"}).Execute() db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) { + db.mu.Lock() + defer db.mu.Unlock() db.CalledQueries = append(db.CalledQueries, sql) } diff --git a/tools/subscriptions/client_test.go b/tools/subscriptions/client_test.go index 1f5a9163..ff5b59b7 100644 --- a/tools/subscriptions/client_test.go +++ b/tools/subscriptions/client_test.go @@ -3,6 +3,7 @@ package subscriptions_test import ( "encoding/json" "strings" + "sync" "testing" "time" @@ -208,12 +209,16 @@ func TestDiscard(t *testing.T) { } func TestSend(t *testing.T) { + var mu sync.Mutex + c := subscriptions.NewDefaultClient() received := []string{} go func() { for m := range c.Channel() { + mu.Lock() received = append(received, m.Name) + mu.Unlock() } }() @@ -226,6 +231,8 @@ func TestSend(t *testing.T) { expected := []string{"m1", "m2"} + mu.Lock() + defer mu.Unlock() if len(received) != len(expected) { t.Fatalf("Expected %d messages, got %d", len(expected), len(received)) }