-
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: stream t.Log output as it happens #24929
Comments
I think we can modify
This will print output immediately, and you get something like this:
It's pretty jumbled, but gets you what you want. |
That would be great 👍 I agree the output is jumbled, but it's actually surprisingly easy to follow so long as each line is prefixed with the test name, and if it's very |
Yea, this is totally OK. Usually, I run that single test when debugging a test. So I don't need to bother about other outputs getting jumbled. I just want the log output to appear immediately. |
I'm skeptical that we can modify -v output, for what little that's worth. |
One more note on the topic of log streaming. It seems that if you run This leads to all the same issues mentioned above, and is especially problematic if you have a single slow package (e.g., one with integration tests), as many CI systems will kill your tests after a certain timeout with no log output (e.g., 10 min in CircleCI). Changing your code doesn't help in this case. The only workaround I've found is to set |
We could argue that the output of |
The redefinition of -v is a bit concerning to me but maybe not enough to sink the idea. |
Is anyone working on an impl? If not, I'll try something this weekend. |
Stream output of t.Log in tests via fmt.Printf if -test.v is set Fixes golang#24929
Change https://golang.org/cl/122581 mentions this issue: |
Change https://golang.org/cl/127120 mentions this issue: |
What's current status? |
Still waiting on for it to be able to make it into Go1.12, I think. @ianlancetaylor is that still some time off? Sorry, I'm not super aware of the timeline. Also I need to rebase, but I'll hold off until it's feasible for it to make it in. |
Timeline is at https://golang.org/wiki/Go-Release-Cycle . The changes now have merge conflicts. Can you resolve those? Thanks. |
Done - will continue conv in gerrit. |
We have a wrapper code that parses the output, and I had to rework that in order to account for this change. I do have a concern with the legibility of the output especially when running multiple tests and subtests. Here's a simple example --
Imagine if there are more tests/subtests that are running in parallel. I understand the original request, but I wish that was done as an optional flag instead of being the default with no way to opt out. Anyways, I'd like to know though if given the current implementation, is it possible for log lines to show up in between result lines, e.g.
?? |
Using an optional flag would just be another knob, and it shouldn't be necessary. People who want something like the old output should be able to run the current output through sed. (I'm not saying the current output is clearly better, I'm just saying that I don't think another knob is the right approach.) I don't think the testing package will ever display |
Thanks for the response. It won't be a simple sed to do exact match for all cases:) Having standard out between result lines can mess up parsing if the output produces fake result lines. Anyways, it's probably not likely. |
Change https://golang.org/cl/219540 mentions this issue: |
We now only accumulate logs when not using -v. Just drop the sentence entirely rather than try to describe the current situation. Updates #24929 Updates #37203 Change-Id: Ie3bf37894ab68b5b129eff54637893c7a129da03 Reviewed-on: https://go-review.googlesource.com/c/go/+/219540 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/226757 mentions this issue: |
See #38458, which suggests changing the format again. |
Change https://golang.org/cl/232157 mentions this issue: |
Change https://golang.org/cl/229085 mentions this issue: |
In #24929, we decided to stream chatty test output. It looks like, foo_test.go:138: TestFoo/sub-1: hello from subtest 1 foo_test.go:138: TestFoo/sub-2: hello from subtest 2 In this CL, we refactor the output to be grouped by === CONT lines, preserving the old test-file-before-log-line behavior: === CONT TestFoo/sub-1 foo_test.go:138 hello from subtest 1 === CONT TestFoo/sub-2 foo_test.go:138 hello from subtest 2 This should remove a layer of verbosity from tests, and make it easier to group together related lines. It also returns to a more familiar format (the pre-streaming format), whilst still preserving the streaming feature. Fixes #38458 Change-Id: Iaef94c580d69cdd541b2ef055aa004f50d72d078 Reviewed-on: https://go-review.googlesource.com/c/go/+/229085 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Andrew Bonventre <andybons@golang.org>
Change https://golang.org/cl/241660 mentions this issue: |
Updates #37419. Updates #38458. Updates #24929. Change-Id: I793bb20fa9db4432fc3a5b69956b7108e4695081 Reviewed-on: https://go-review.googlesource.com/c/go/+/241660 Run-TryBot: Jean de Klerk <deklerk@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Change https://golang.org/cl/242057 mentions this issue: |
In #24929, we decided to stream chatty test output. It looks like, foo_test.go:138: TestFoo/sub-1: hello from subtest 1 foo_test.go:138: TestFoo/sub-2: hello from subtest 2 In this CL, we refactor the output to be grouped by === CONT lines, preserving the old test-file-before-log-line behavior: === CONT TestFoo/sub-1 foo_test.go:138 hello from subtest 1 === CONT TestFoo/sub-2 foo_test.go:138 hello from subtest 2 This should remove a layer of verbosity from tests, and make it easier to group together related lines. It also returns to a more familiar format (the pre-streaming format), whilst still preserving the streaming feature. Updates #38458. Fixes #39308. Change-Id: Iaef94c580d69cdd541b2ef055aa004f50d72d078 Reviewed-on: https://go-review.googlesource.com/c/go/+/229085 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Andrew Bonventre <andybons@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/242057 Reviewed-by: Jean de Klerk <deklerk@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Jean de Klerk <deklerk@google.com>
As suggested in #23213 (comment), I'm filing a new issue with a proposal for how to improve
t.Log
andt.Logf
.What version of Go are you using (
go version
)?go version go1.9.2
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?I'm on Darwin, amd64, but this affects all systems/architectures.
Motivation
Consider the following (silly) automated tests:
If I run
go test -v
, I get no log output until all ofTestFoo
is done, then no output until all ofTestBar
is done, and again no more output until all ofTestBaz
is done. This is fine if the tests are working, but if there is some sort of bug, there are a few cases where buffering log output is problematic:TestFoo
is slow (e.g., it's an integration test), I get no log output until the very end of the test. This significantly slows down iteration.TestFoo
has a bug that causes it to hang and never complete, I'd get no log output whatsoever. In these cases,t.Log
andt.Logf
are of no use at all. This makes debugging very difficult.Current workarounds
The main workaround is to replace all
t.Logf
calls with eitherfmt.Printf
or a custom logger. Since we often want to iterate quickly on tests, and since debugging is such an important use case, in practice, that means we never uset.Logf
at all.This seems like a missed opportunity. Go has a lot of powerful testing tools built in, and we usually pass the
t
variable around to many test methods so they can callt.Fatal()
,t.Name()
, etc. It would be great ift
had a logger built in that we could actually use. Honestly, the only thing it's really missing is some way to configure the logger to write tostdout
immediately, rather than buffering.Possible solutions
Probably the easiest way to improve
t.Log
andt.Logf
is to add a-test.streamlogs
option to thego test
command. When this option is set,t.Log
andt.Logf
write tostdout
immediately, instead of buffering.This means the output format with this option set wouldn't be backwards compatible, but the expectation is that this option would only be used for local debugging, and not something used in your CI system.
The text was updated successfully, but these errors were encountered: