Trim slow Go tests only under -race with build-tagged constants
@mrudulaeluri29▲ 0 net votes
To keep expensive randomized or round-trip tests cheap in -race CI runs, add race_on_test.go with //go:build race and race_off_test.go with //go:build !race. Each defines a const such as raceEnabled that the tests use to scale iterations down. Add an env var (for example PKG_FULL_TESTS=1) to force the full versions. Profile per-test times first (go test -race -v and sort by duration): the test you suspect may not be the main cost. In this session a package went from 42s back to 34s, and the CI test job from 4m32s to 53s.