-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: writing to os.Stderr pollutes test names in go test -json
output
#33419
Comments
It's not clear to me that there is anything we can do about this. |
I had a pretty hard time following the If so, I expected the json output option to be passed down to test/subtests processes, and for them to output json the package-level would aggregate (and maybe supplement with package-level info), rather than invoke them normally and try to untangle their output. |
I'm not sure what you mean by "the package level."
|
I thought the invocations of the test binary were once per tested package, but I may have misread the test runner.
If the output could be reliably parsed by test2json, I'd agree, but in practice, it cannot. Maybe it doesn't need to know it is outputting to be parsed by test2json, but if it is treating stderr as a structured communication channel, it needs to take measures to prevent interleaving.
no goroutine with a lifetime spanning tests or subtests being able to use os.Stderr is a pretty surprising requirement for |
You are correct: a separate test binary is built for each package.
Well, I'm certainly not opposed to fixing it if we can. That said, I actually can't recreate the problem. When I run |
It's racy, and maybe load dependent? I usually had to run with -count greater than 1 to capture it.
Yeah, that doesn't matter. We encounter it regularly in CI on Linux - |
Interestingly, for normal use of stderr that writes complete lines, forcing test output to only go to stdout resolves the issue ( Letting the package test executable write independent stdout/stderr streams, then joining them without regard for linebreaks (which is what it looks like the exec package does when the same writer is assigned to cmd.Stdout and cmd.Stderr) is what is turning well-behaved independent stderr and stdout writes by the test executable into a single interleaved stream. |
I think this is related to #23036. |
I think you're right that we could fix that if cmd/go did not merge stdout and stderr together. We should probably handle test stderr output by arranging for it to flow directly into the test2json Output field. Somehow. |
@liggitt background:In minikube we use 'go tool test2json' to procude json output and then use a tool called gopopgh to convert it to human-friendly HTML. in running minikube's e2e in powershell we have noticed that the tests talk over each other. here we see that inside "TestFunctional/parallel/PersistentVolumeClaim" there is logs from TestFunctional/parallel/MountCmd
The exact command to produce the json passed to golang's test binary as see here
and here is the exact command that we use to convert the .txt file to json in powershel
Log files:here I paste the full .txt an and .json files in a gist https://gist.github.com/medyagh/2d681788e5e6491b8fc735b2ed0454dc Footnote1:I had to add do you think this is related to this bug or or is it more related to this #29811 ? |
Related to #26325 |
Change https://go.dev/cl/443596 mentions this issue: |
Test2json is parsing the output stream from the test, which includes package testing's own framing lines intermingled with other output, in particular any output printed via fmt.Printf, println, and so on. We have had recurring problems with unexpected partial output lines causing a framing line to be missed. A recent talk at GopherCon gave an example of an integration test involving Docker that happened to print \r-terminated lines instead of \n-terminated lines in some configurations, which in turn broke test2json badly. (https://www.gophercon.com/agenda/session/944259) There are also a variety of open reported issues with similar problems, which this CL also addresses. The general approach is to add a new testing flag -test.v=json that means to print additional output to help test2json. And then test2json takes advantage of that output. Among the fixes: - Identify testing framing more reliably, using ^V (golang#23036, golang#26325, golang#43683, GopherCon talk) - Test that output with \r\n endings is handled correctly (golang#43683, golang#34286) - Use === RUN in fuzz tests (golang#52636, golang#48132) - Add === RUN lines to note benchmark starts (golang#27764, golang#49505) - Print subtest --- PASS/FAIL lines as they happen (golang#29811) - Add === NAME lines to emit more test change events, such as when a subtest stops and the parent continues running. - Fix event shown in overall test failure (golang#27568) - Avoid interleaving of writes to os.Stdout and os.Stderr (golang#33419) Fixes golang#23036. Fixes golang#26325. Fixes golang#27568. Fixes golang#27764. Fixes golang#29811. Fixes golang#33419. Fixes golang#34286. Fixes golang#43683. Fixes golang#49505. Fixes golang#52636. Change-Id: Id4207b746a20693f92e52d68c6e4a7f8c41cc7c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/443596 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
We have go tests that start a server goroutine running in the background, then run subtests against that server. The server goroutine can log to stdout/stderr.
To obtain structured test output, we run go tests with
-json
to cleanly separate test names, status, and output.The following example reproduces the issue:
stdout_test.go:
What did you expect to see?
Correct test name and status in
go test -json
outputWhat did you see instead?
Stderr output from the server goroutine interleaved with test names inside the structured json data.
Observations:
go test -json
not outputting test names with fidelity messes up systems that transform that output to junit format or ingest it into tools like testgrid that show history of a particular testThe text was updated successfully, but these errors were encountered: