-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
testutil: NewLogBuffer - buffer logs until a test fails #7948
Conversation
Another nice property of this approach seems to be that when multiple agents are run in a test case, all of the logs for a single agent are grouped together. I suspect previously they would have been interspersed. It also means that all assertion failures will appear first before any logs, which should make them easier to find in the output. |
7312c44
to
3e038dd
Compare
Replaces #7559 Running tests in parallel, with background goroutines, results in test output not being associated with the correct test. `go test` does not make any guarantees about output from goroutines being attributed to the correct test case. Attaching log output from background goroutines also cause data races. If the goroutine outlives the test, it will race with the test being marked done. Previously this was noticed as a panic when logging, but with the race detector enabled it is shown as a data race. The previous solution did not address the problem of correct test attribution because test output could still be hidden when it was associated with a test that did not fail. You would have to look at all of the log output to find the relevant lines. It also made debugging test failures more difficult because each log line was very long. This commit attempts a new approach. Instead of printing all the logs, only print when a test fails. This should work well when there are a small number of failures, but may not work well when there are many test failures at the same time. In those cases the failures are unlikely a result of a specific test, and the log output is likely less useful. All of the logs are printed from the test goroutine, so they should be associated with the correct test. Also removes some test helpers that were not used, or only had a single caller. Packages which expose many functions with similar names can be difficult to use correctly. Related: golang/go#38458 (may be fixed in go1.15) golang/go#38382 (comment)
3e038dd
to
51efba2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🍒✅ Cherry pick of commit 3570ce6 onto |
testutil: NewLogBuffer - buffer logs until a test fails
Replaces #7559
Fixes this data race (and likely many others): #8329 (comment)
Running tests in parallel, with background goroutines, results in test output not being associated with the correct test.
go test
does not make any guarantees about output from goroutines being attributed to the correct test case.Attaching log output from background goroutines also cause data races. If the goroutine outlives the test, it will race with the test being marked done. Previously this was noticed as a panic when logging, but with the race detector enabled it is shown as a data race.
This commit attempts a new approach. Instead of printing all the logs, only print when a test fails. All of the logs are printed from the test goroutine, so they should be associated with the correct test.
Another nice property of this approach is that when multiple agents are run in a test case, all of the logs for a single agent are grouped together. Previously they would have been interspersed.
Also removes some test helpers that were not used, or only had a single caller. Packages which expose many functions with similar names can be difficult to use correctly.
Tested some of the data races locally with
-count=100
to ensure they no long race with this change.Related:
golang/go#38458 (a regression in go1.14 that was just fixed in go1.14.6)
golang/go#38382 (comment)