Skip to content

Make the race tests 7x faster by skipping the race detector's exit sleep in the fake CLI - #5

Merged
akash-aman merged 1 commit into
mainfrom
test/race-exit-sleep
Oct 12, 2026
Merged

akash-aman merged 1 commit into
mainfrom
test/race-exit-sleep

Conversation

@akash-aman

Copy link
Copy Markdown
Collaborator

Summary

  • Cause: a -race binary sleeps for GORACE atexit_sleep_ms (1000 ms by default) when it exits with status 0, to catch races at exit. The fake agent-browser is the test binary run once per CLI call, so every fake call slept a second.
    • An empty func main(){} built with -race takes 1,087 ms against 6 ms without, using no CPU.
    • A stack sample shows the main thread in runtime.main → __tsan::Finalize → usleep.
    • CI was slower still (282 s for the tools package) because a 4-CPU runner runs 4 parallel tests at a time.
  • Fix: the fake exits with syscall.Exit, which skips that shutdown (internal/testutil/fakecli/fakecli.go). The code under test is still race-checked in the test process; only the fake skips it.
go test -race (16-core Mac) Before After
internal/mcp/tools 78.9 s 9.6 s
internal/browser 6.0 s 1.8 s
internal/devtools 7.3 s 3.8 s
./... (wall) about 80 s 11.9 s

Test plan

  • go test -race -count=1 ./... five times in a row: all pass, tools 10.3–11.1 s
  • go test -count=1 ./... and go vet ./..., gofmt -l clean
  • CI: runs once Publish releases with GoReleaser on version tags #4 (which adds the CI workflow) is merged; the race-test step should drop from about 5 minutes to under one

A -race binary sleeps for GORACE atexit_sleep_ms (one second by default)
when it exits with status 0, to catch races at exit. The fake
agent-browser is the test binary run once per CLI call, so every call
slept a second: the tools tests took 79s with -race here and 282s on a
4-CPU CI runner, against 3.4s without -race.

The fake now exits with syscall.Exit, which skips that shutdown. The
code under test is still race-checked in the test process. With -race
the tools package takes about 10s and the whole suite about 12s.
@akash-aman
akash-aman merged commit 427f3aa into main Oct 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant