Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: test output interleaves with race-detector warnings #29156

Closed
mfridman opened this issue Dec 8, 2018 · 3 comments
Closed

testing: test output interleaves with race-detector warnings #29156

mfridman opened this issue Dec 8, 2018 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mfridman
Copy link

mfridman commented Dec 8, 2018

What version of Go are you using (go version)?

go version devel +353795c839 Sat Dec 8 00:27:08 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

N/A. Built from source.

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOOS="darwin"

What did you do?

Running go test -count=1 -json -race produces output that's difficult for downstream tools to parse.

https://play.golang.org/p/hpTaOLoTNcL

The reports --- FAIL line may appear anywhere between the goal posts:

================== <- goal post
WARNING: DATA RACE
...
==================

What did you expect to see?

I'd expect a uniform method of outputting tests detected by -race as true. Whether the non-race output is before or after is irrelevant, but it should be consistent.

--- FAIL: TestRace1 (0.00s)                                                  <- HERE
    some_test.go:10: 64
    testing.go:806: race detected during execution of test
==================
WARNING: DATA RACE

// would only expected output related to the DATA RACE

==================
--- FAIL: TestRace1 (0.00s)                                                  <- OR HERE
    some_test.go:10: 64
    testing.go:806: race detected during execution of test

What did you see instead?

The --- FAIL line can appear in random places throughout the output:

Example 1:

==================
WARNING: DATA RACE
Write at 0x00c000014160 by goroutine 12:
  debug/tparse-24.TestRace1.func1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:8 +0x38

Previous write at 0x00c000014160 by goroutine 6:
  debug/tparse-24.TestRace1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:9 +0x96
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Goroutine 12 (running) created at:
  debug/tparse-24.TestRace1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:8 +0x88
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
--- FAIL: TestRace1 (0.00s)                                                  <- HERE
    some_test.go:10: 64
    testing.go:771: race detected during execution of test

Goroutine 6 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:878 +0x650
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1119 +0xa8
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1117 +0x4ee
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1034 +0x2ee
  main.main()
      _testmain.go:48 +0x221
==================

Example 2 (full):

=== RUN   TestRace1
=== PAUSE TestRace1
=== RUN   TestRace2
=== PAUSE TestRace2
=== RUN   TestA
=== PAUSE TestA
=== RUN   TestB
=== PAUSE TestB
=== CONT  TestRace1
=== CONT  TestB
=== CONT  TestRace2
--- PASS: TestB (0.00s)
=== CONT  TestA
--- PASS: TestA (0.00s)
==================
WARNING: DATA RACE
Write at 0x00c0000c2010 by goroutine 11:
  debug/tparse-24.TestRace2.func1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:15 +0x38

Previous write at 0x00c0000c2010 by goroutine 7:
  debug/tparse-24.TestRace2()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:16 +0xaa
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Goroutine 11 (running) created at:
  debug/tparse-24.TestRace2()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:15 +0x9c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Goroutine 7 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:878 +0x650
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1119 +0xa8
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1117 +0x4ee
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1034 +0x2ee
  main.main()
      _testmain.go:48 +0x221
==================
--- FAIL: TestRace2 (0.00s)
    some_test.go:17: 64
    some_test.go:19: 64
    some_test.go:22: 64
    some_test.go:25: 64
    some_test.go:28: 64
    some_test.go:31: 64
    some_test.go:34: 64
    some_test.go:37: 64
    some_test.go:40: 64
    some_test.go:43: 64
    some_test.go:46: 64
    some_test.go:49: 12
    some_test.go:52: 12
    testing.go:771: race detected during execution of test
==================
WARNING: DATA RACE
Write at 0x00c000014160 by goroutine 12:
  debug/tparse-24.TestRace1.func1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:8 +0x38

Previous write at 0x00c000014160 by goroutine 6:
  debug/tparse-24.TestRace1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:9 +0x96
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Goroutine 12 (running) created at:
  debug/tparse-24.TestRace1()
      /Users/michael.fridman/go/src/debug/tparse-24/some_test.go:8 +0x88
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
--- FAIL: TestRace1 (0.00s)                                                  <- HERE
    some_test.go:10: 64
    testing.go:771: race detected during execution of test

Goroutine 6 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:878 +0x650
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1119 +0xa8
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1117 +0x4ee
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1034 +0x2ee
  main.main()
      _testmain.go:48 +0x221
==================
FAIL
exit status 1
FAIL	debug/tparse-24	0.018s
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 8, 2018
@agnivade agnivade added this to the Go1.13 milestone Dec 8, 2018
@mfridman
Copy link
Author

mfridman commented Dec 8, 2018

It appears data race output is printed as soon as it's detected.

Whatever test the go tool is running at that time will "own" the data race output, which means it'll get lumped in seemingly random places.

@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

This is not a cmd/go issue. The problem is that the test binary itself writes output to stderr, and the race detector also writes to stderr, and there is no active synchronization between the two.

See also #24929.

@bcmills bcmills changed the title cmd/go: standardize reporting of go test -race output testing: test output interleaves with race-detector warnings Jan 17, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

CC @mpvl @josharian

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@mfridman mfridman closed this as completed Feb 8, 2024
@mfridman mfridman closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants