test(openai): set Gin mode once per package - #179
Merged
Conversation
Per-test gin.SetMode(gin.TestMode) calls race under parallel tests: concurrent writes to the package-global gin mode while other parallel tests read it via gin.New/CreateTestContext. Set it once in TestMain instead and drop the 59 per-test calls.
Contributor
Author
Evidence — race fixed, plus CI build check classificationChange (accepted CPA port, functionally isolated to openai tests)
Pre-fix race (reproduced on unmodified base
|
Contributor
Author
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
added 2 commits
August 15, 2026 08:39
No code change. Previous build run failed on a transient websocket close 1006 unexpected EOF in the test environment.
No code change. TestWebsocketRetryBindFailureClearsActiveSessionState passes 30/30 locally; CI failure is a timing-sensitive flake.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port the accepted CPA gin test-mode race fix to CPAPlus. Sets
gin.TestModeonce in a package-levelTestMainand removes 59 per-testgin.SetMode(gin.TestMode)calls across 9 test files insdk/api/handlers/openai.Why (race)
The per-test
gin.SetMode(gin.TestMode)calls race under parallel tests: parallel tests write the package-global gin mode (ginpackagemodevar) while other parallel tests read it throughgin.New/gin.CreateTestContext. The result is a data race flagged bygo test -race.Reproduced pre-fix (unmodified base, this branch's base
4823235a)go test -race -count=2 -run 'TestPrepareCodexMultiAgentV2ToolsAtResponsesBoundary$|TestResponsesPreparesCodexMultiAgentV2ToolsForHTTPAndSSE|TestPrepareCodexMultiAgentV2ToolsAtResponsesBoundarySkipsOtherClients' ./sdk/api/handlers/openai/Change
sdk/api/handlers/openai/gin_testmode_test.go— packageopenai,TestMainthat callsgin.SetMode(gin.TestMode)once beforeos.Exit(m.Run()).gin.SetMode(gin.TestMode)calls (write-write race source) from:gitlab_duo_handler_test.go(2)openai_images_handlers_test.go(1)openai_responses_compact_test.go(3)openai_responses_handlers_stream_error_test.go(5)openai_responses_handlers_stream_test.go(2)openai_responses_multi_agent_test.go(3)openai_responses_signature_test.go(2)openai_responses_websocket_test.go(35)openai_videos_handlers_test.go(6)t.Parallel()and allginimports preserved (still used bygin.New/gin.CreateTestContext).Stat:
10 files changed, 18 insertions(+), 59 deletions(-).Verification (all green)
-count=3(the 3 parallel multi-agent tests):ok, no DATA RACE.-count=1:ok.ok.go test ./...: exit 0.go build ./...: exit 0.go vet ./sdk/api/handlers/openai/: exit 0.gofmtclean;git diff --checkclean.TestMain, exactly 1 realgin.SetMode(gin.TestMode)(inTestMain), zero per-test calls.Functionally isolated from #175 (author-failover-recovery) — different branch (
fix/gin-testmode-race), test-infrastructure only, no production code.Mirror
CPA: router-for-me/CLIProxyAPI#4948 (identical changes)