MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestRaceAttributedToPassingTest

Function TestRaceAttributedToPassingTest

cmd/testwrapper/testwrapper_test.go:279–321  ·  view source on GitHub ↗

TestRaceAttributedToPassingTest covers the case where go test attributes a data race report to a test that itself reports PASS (e.g. when the racing goroutines outlive the test that spawned them and TSan prints during a different test's window). Without the race-detection fix, the WARNING: DATA RACE

(t *testing.T)

Source from the content-addressed store, hash-verified

277// stuck in a passing test's log buffer and dropped on the floor.
278// See https://github.com/tailscale/tailscale/issues/19603.
279func TestRaceAttributedToPassingTest(t *testing.T) {
280 if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
281 t.Skip("test requires the race detector, which needs linux/amd64")
282 }
283 t.Parallel()
284
285 testfile := filepath.Join(t.TempDir(), "race_test.go")
286 code := []byte(`package race_test
287
288import (
289 "sync"
290 "testing"
291)
292
293var counter int
294var wg sync.WaitGroup
295
296func TestSpawn(t *testing.T) {
297 wg.Add(2)
298 go func() { defer wg.Done(); counter++ }()
299 go func() { defer wg.Done(); counter++ }()
300}
301
302func TestWait(t *testing.T) {
303 wg.Wait()
304}
305`)
306 if err := os.WriteFile(testfile, code, 0o644); err != nil {
307 t.Fatalf("writing package: %s", err)
308 }
309
310 out, err := cmdTestwrapper(t, testfile, "-race").CombinedOutput()
311 if code, ok := errExitCode(err); !ok || code != 1 {
312 t.Fatalf("testwrapper %s -race: expected exit code 1, got %v; output was:\n%s", testfile, err, out)
313 }
314 if want := "WARNING: DATA RACE"; !bytes.Contains(out, []byte(want)) {
315 t.Fatalf("expected race report in output, got:\n%s", out)
316 }
317
318 if testing.Verbose() {
319 t.Logf("success - output:\n%s", out)
320 }
321}
322
323func TestBuildError(t *testing.T) {
324 t.Parallel()

Callers

nothing calls this directly

Calls 9

cmdTestwrapperFunction · 0.85
errExitCodeFunction · 0.85
CombinedOutputMethod · 0.80
SkipMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalfMethod · 0.65
LogfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…