mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-29 19:18:57 -04:00
A data race in a package matters more than any individual test
result. Two related problems:
1. Where go test's race detector text ("WARNING: DATA RACE" plus
the goroutine stack traces) lands in JSON output is timing-
dependent: it can be attributed to a test that ends up reporting
PASS (e.g. when the racing goroutines outlive the test that
spawned them and TSan prints during a different test's window).
testwrapper's main loop only flushes the logs of failed tests,
so the race report ends up stuck in a passing test's buffer and
is silently dropped. The race builders just see a bare
"FAIL\nFAIL\tpkg\ttime".
2. If the failing test in such a package happens to be marked flaky,
testwrapper retries it. That is the worst possible response to a
race: the flaky test might not even be the racy code, and a
second run without the racy goroutines could "succeed" while
hiding the real bug.
Address both: scan every output line for the race detector's first-
line marker. Track whether the package observed a race at all, on
the pkgFinished testAttempt. When a race was seen, fold every per-
test log buffer into the package-level logs (so the full report
surfaces from the existing pkg-fail flush path), and drop any
flaky-test retry plans for that package so we fail immediately
instead of running another attempt.
Two new tests:
- TestRaceSuppressesFlakyRetry verifies that a flaky test alongside
a racy test does NOT get retried.
- TestRaceAttributedToPassingTest verifies that a race attributed by
test2json to a passing test still surfaces in the output.
Also add a corpus of captured raw test binary outputs under
cmd/testwrapper/testdata/, with one subdirectory per scenario,
documenting the six representative shapes that go test -race can
emit (race in test body, race in goroutines that outlive a test,
race forced into a later test, race in TestMain post-m.Run, and a
parallel-tests split-attribution case via a "=== NAME" redirect
line). See its README.md for details.
Fixes #19603
Change-Id: Ifbfcd67fb3b1882c4907bd9cb2d68a8b5a91dd54
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
58 lines
1.9 KiB
Plaintext
58 lines
1.9 KiB
Plaintext
=== RUN TestParA
|
|
=== PAUSE TestParA
|
|
=== RUN TestParB
|
|
=== PAUSE TestParB
|
|
=== CONT TestParA
|
|
=== CONT TestParB
|
|
--- PASS: TestParA (0.00s)
|
|
==================
|
|
WARNING: DATA RACE
|
|
Read at 0x0000007f02b0 by goroutine 8:
|
|
racesurvey/F_parallel.TestParB()
|
|
/tmp/racesurvey/F_parallel/f_test.go:17 +0x3b
|
|
testing.tRunner()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2036 +0x21c
|
|
testing.(*T).Run.gowrap1()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2101 +0x38
|
|
|
|
Previous write at 0x0000007f02b0 by goroutine 7:
|
|
racesurvey/F_parallel.TestParA()
|
|
/tmp/racesurvey/F_parallel/f_test.go:10 +0x53
|
|
testing.tRunner()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2036 +0x21c
|
|
testing.(*T).Run.gowrap1()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2101 +0x38
|
|
|
|
Goroutine 8 (running) created at:
|
|
testing.(*T).Run()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2101 +0xb12
|
|
testing.runTests.func1()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2585 +0x84
|
|
testing.tRunner()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2036 +0x21c
|
|
testing.runTests()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2583 +0x9e9
|
|
testing.(*M).Run()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2443 +0xf4b
|
|
main.main()
|
|
_testmain.go:48 +0x164
|
|
|
|
Goroutine 7 (running) created at:
|
|
testing.(*T).Run()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2101 +0xb12
|
|
testing.runTests.func1()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2585 +0x84
|
|
testing.tRunner()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2036 +0x21c
|
|
testing.runTests()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2583 +0x9e9
|
|
testing.(*M).Run()
|
|
/home/ubuntu/sdk/go1.26.3/src/testing/testing.go:2443 +0xf4b
|
|
main.main()
|
|
_testmain.go:48 +0x164
|
|
==================
|
|
=== NAME TestParB
|
|
testing.go:1712: race detected during execution of test
|
|
--- FAIL: TestParB (0.00s)
|
|
FAIL
|