-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit 212b76d
Reporting subtests as they finish (#4250)
**What type of PR is this?**
Feature
**What does this PR do? Why is it needed?**
This PR makes rules_go report all finished subtests in the XML file,
even when the test target times out. It does this by adding
`-test.v=test2json` when verbose mode is requested. According to [Go's
comment](https://github.com/golang/go/blob/go1.23.2/src/testing/testing.go#L836):
> If test2json is used, we never flush to parent tests, so that the json
stream shows subtests as they finish.
It also sync test2json.go from upstream golang/go.
With a test file like this:
```go
package test_report
import (
"fmt"
"testing"
"time"
)
func TestReport(t *testing.T) {
for i := 0; i < 10; i++ {
t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) {
time.Sleep(2 * time.Second)
})
}
}
```
Running with `--test_timeout=10 --test_env=GO_TEST_WRAP_TESTV=1`, the
XML before the PR:
```xml
<testsuites>
<testsuite errors="6" failures="0" skipped="0" tests="6" time="" name="example.com/test_report/go_default_test">
<testcase classname="go_default_test" name="TestReport" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_0" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_0
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_1" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_1
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_2" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_2
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_3" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_3
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_4" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_4
panic: test timed out after 10s
	running tests:
		TestReport (10s)
		TestReport/test_4 (2s)

goroutine 22 [running]:
testing.(*M).startAlarm.func1()
	GOROOT/src/testing/testing.go:2373 +0x385
created by time.goFunc
	GOROOT/src/time/sleep.go:215 +0x2d

goroutine 1 [chan receive]:
testing.(*T).Run(0xc0001aa000, {0x5b8d09?, 0x0?}, 0x5db1c0)
	GOROOT/src/testing/testing.go:1751 +0x3ab
testing.runTests.func1(0xc0001aa000)
	GOROOT/src/testing/testing.go:2168 +0x37
testing.tRunner(0xc0001aa000, 0xc00015cb18)
	GOROOT/src/testing/testing.go:1690 +0xf4
testing.runTests(0xc0001a2000, {0x712a50, 0x1, 0x1}, {0xc00015cb48?, 0x16?, 0x721b00?})
	GOROOT/src/testing/testing.go:2166 +0x43d
testing.(*M).Run(0xc0001521e0)
	GOROOT/src/testing/testing.go:2034 +0x64a
go.uber.org/goleak.VerifyTestMain({0x60dc20?, 0xc0001521e0?}, {0x0, 0x0, 0x0})
	external/org_uber_go_goleak/testmain.go:53 +0x5a
main.main()
	bazel-out/k8-fastbuild/bin/src/code.uber.internal/devexp/test_report/go_default_test_/testmain.go:130 +0x355

goroutine 17 [syscall]:
os/signal.signal_recv()
	GOROOT/src/runtime/sigqueue.go:152 +0x29
os/signal.loop()
	GOROOT/src/os/signal/signal_unix.go:23 +0x13
created by os/signal.Notify.func1.1 in goroutine 1
	GOROOT/src/os/signal/signal.go:151 +0x1f

goroutine 18 [chan receive]:
testing.(*T).Run(0xc0001aa1a0, {0xc000282060?, 0xc00015cf50?}, 0x5db310)
	GOROOT/src/testing/testing.go:1751 +0x3ab
src/code.uber.internal/devexp/test_report/go_default_test.TestReport(0xc0001aa1a0)
	src/code.uber.internal/devexp/test_report/a_test.go:11 +0x74
testing.tRunner(0xc0001aa1a0, 0x5db1c0)
	GOROOT/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	GOROOT/src/testing/testing.go:1743 +0x390

goroutine 34 [sleep]:
time.Sleep(0x77359400)
	GOROOT/src/runtime/time.go:315 +0xf2
src/code.uber.internal/devexp/test_report/go_default_test.TestReport.func1(0xc0002961a0?)
	src/code.uber.internal/devexp/test_report/a_test.go:12 +0x18
testing.tRunner(0xc0002961a0, 0x5db310)
	GOROOT/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 18
	GOROOT/src/testing/testing.go:1743 +0x390
</error>
</testcase>
</testsuite>
</testsuites>
```
The XML after the PR:
```xml
<testsuites>
<testsuite errors="2" failures="0" skipped="0" tests="6" time="" name="example.com/test_report/go_default_test">
<testcase classname="go_default_test" name="TestReport" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport
</error>
</testcase>
<testcase classname="go_default_test" name="TestReport/test_0" time="2.000"></testcase>
<testcase classname="go_default_test" name="TestReport/test_1" time="2.000"></testcase>
<testcase classname="go_default_test" name="TestReport/test_2" time="2.000"></testcase>
<testcase classname="go_default_test" name="TestReport/test_3" time="2.000"></testcase>
<testcase classname="go_default_test" name="TestReport/test_4" time="">
<error message="No pass/skip/fail event found for test" type="">=== RUN TestReport/test_4
panic: test timed out after 10s
	running tests:
		TestReport (10s)
		TestReport/test_4 (2s)

goroutine 21 [running]:
testing.(*M).startAlarm.func1()
	GOROOT/src/testing/testing.go:2373 +0x385
created by time.goFunc
	GOROOT/src/time/sleep.go:215 +0x2d

goroutine 1 [chan receive]:
testing.(*T).Run(0xc0001aa000, {0x5b8d07?, 0x0?}, 0x5db1d0)
	GOROOT/src/testing/testing.go:1751 +0x3ab
testing.runTests.func1(0xc0001aa000)
	GOROOT/src/testing/testing.go:2168 +0x37
testing.tRunner(0xc0001aa000, 0xc00015cb18)
	GOROOT/src/testing/testing.go:1690 +0xf4
testing.runTests(0xc0001a2000, {0x712a50, 0x1, 0x1}, {0xc00015cb48?, 0x16?, 0x721b00?})
	GOROOT/src/testing/testing.go:2166 +0x43d
testing.(*M).Run(0xc0001521e0)
	GOROOT/src/testing/testing.go:2034 +0x64a
go.uber.org/goleak.VerifyTestMain({0x60dc40?, 0xc0001521e0?}, {0x0, 0x0, 0x0})
	external/org_uber_go_goleak/testmain.go:53 +0x5a
main.main()
	bazel-out/k8-fastbuild/bin/src/code.uber.internal/devexp/test_report/go_default_test_/testmain.go:130 +0x355

goroutine 17 [syscall]:
os/signal.signal_recv()
	GOROOT/src/runtime/sigqueue.go:152 +0x29
os/signal.loop()
	GOROOT/src/os/signal/signal_unix.go:23 +0x13
created by os/signal.Notify.func1.1 in goroutine 1
	GOROOT/src/os/signal/signal.go:151 +0x1f

goroutine 18 [chan receive]:
testing.(*T).Run(0xc0001aa1a0, {0xc000282086?, 0xc00015cf50?}, 0x5db320)
	GOROOT/src/testing/testing.go:1751 +0x3ab
src/code.uber.internal/devexp/test_report/go_default_test.TestReport(0xc0001aa1a0)
	src/code.uber.internal/devexp/test_report/a_test.go:11 +0x74
testing.tRunner(0xc0001aa1a0, 0x5db1d0)
	GOROOT/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	GOROOT/src/testing/testing.go:1743 +0x390

goroutine 35 [sleep]:
time.Sleep(0x77359400)
	GOROOT/src/runtime/time.go:315 +0xf2
src/code.uber.internal/devexp/test_report/go_default_test.TestReport.func1(0xc000294340?)
	src/code.uber.internal/devexp/test_report/a_test.go:12 +0x18
testing.tRunner(0xc000294340, 0x5db320)
	GOROOT/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 18
	GOROOT/src/testing/testing.go:1743 +0x390
</error>
</testcase>
</testsuite>
</testsuites>
```
---------
Co-authored-by: Jay Conrod <[email protected]>1 parent 8c95bcf commit 212b76dCopy full SHA for 212b76d
File tree
Expand file treeCollapse file tree
1 file changed
+4
-1
lines changedFilter options
- go/tools/bzltestutil
Expand file treeCollapse file tree
1 file changed
+4
-1
lines changedgo/tools/bzltestutil/wrap.go
Copy file name to clipboardExpand all lines: go/tools/bzltestutil/wrap.go+4-1Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
118 | 118 |
| |
119 | 119 |
| |
120 | 120 |
| |
121 |
| - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
122 | 125 |
| |
123 | 126 |
| |
124 | 127 |
| |
|
0 commit comments