From 9647d7fb161ba2d9049fe3b42cf69e321bd85985 Mon Sep 17 00:00:00 2001 From: jedarden Date: Mon, 25 May 2026 20:37:57 -0400 Subject: [PATCH] fix(engine): resolve race condition in TestIntegration_CenterWeightedEnergy The test was using the same HTTPBot instance for both players, causing concurrent access to HTTPBot fields (turn, crashed, failCount, lastDebug). Fixed by creating separate bot instances with different BotIDs. This resolves the race detected by -race: WARNING: DATA RACE Write at 0x... by goroutine 475: github.com/aicodebattle/acb/engine.(*HTTPBot).GetMoves() Previous write at 0x... by goroutine 474: github.com/aicodebattle/acb/engine.(*HTTPBot).GetMoves() --- engine/integration_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/integration_test.go b/engine/integration_test.go index d428db2..113ae36 100644 --- a/engine/integration_test.go +++ b/engine/integration_test.go @@ -204,9 +204,6 @@ func TestIntegration_CenterWeightedEnergy(t *testing.T) { server := createMockBotServer(t, secret, 0) defer server.Close() - auth := AuthConfig{BotID: "b_test", Secret: secret, MatchID: "m_energy_test"} - bot := NewHTTPBot(server.URL, auth, WithHTTPTimeout(5*time.Second)) - config := DefaultConfig() config.Rows = 60 config.Cols = 60 @@ -217,8 +214,14 @@ func TestIntegration_CenterWeightedEnergy(t *testing.T) { WithTimeout(5*time.Second), ) - runner.AddBot(bot, "TestBot") - runner.AddBot(bot, "TestBot2") + // Use separate bot instances to avoid race conditions + auth1 := AuthConfig{BotID: "b_test1", Secret: secret, MatchID: "m_energy_test"} + bot1 := NewHTTPBot(server.URL, auth1, WithHTTPTimeout(5*time.Second)) + auth2 := AuthConfig{BotID: "b_test2", Secret: secret, MatchID: "m_energy_test"} + bot2 := NewHTTPBot(server.URL, auth2, WithHTTPTimeout(5*time.Second)) + + runner.AddBot(bot1, "TestBot") + runner.AddBot(bot2, "TestBot2") result, replay, err := runner.Run() if err != nil {