mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing, testing/synctest: report correct duration after panics
Report the correct wall-clock test duration after handling a panic in a synctest.Test bubble. Fixes #73852 Change-Id: I053262e5eac2dd9d5938b17c3093cbc3fa115a0d Reviewed-on: https://go-review.googlesource.com/c/go/+/676695 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
29782bd347
commit
8cd7f17248
2 changed files with 12 additions and 4 deletions
|
|
@ -273,13 +273,19 @@ import (
|
||||||
// associated with the bubble.
|
// associated with the bubble.
|
||||||
// - T.Run, T.Parallel, and T.Deadline must not be called.
|
// - T.Run, T.Parallel, and T.Deadline must not be called.
|
||||||
func Test(t *testing.T, f func(*testing.T)) {
|
func Test(t *testing.T, f func(*testing.T)) {
|
||||||
|
var ok bool
|
||||||
synctest.Run(func() {
|
synctest.Run(func() {
|
||||||
testingSynctestTest(t, f)
|
ok = testingSynctestTest(t, f)
|
||||||
})
|
})
|
||||||
|
if !ok {
|
||||||
|
// Fail the test outside the bubble,
|
||||||
|
// so test durations get set using real time.
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:linkname testingSynctestTest testing/synctest.testingSynctestTest
|
//go:linkname testingSynctestTest testing/synctest.testingSynctestTest
|
||||||
func testingSynctestTest(t *testing.T, f func(*testing.T))
|
func testingSynctestTest(t *testing.T, f func(*testing.T)) bool
|
||||||
|
|
||||||
// Wait blocks until every goroutine within the current bubble,
|
// Wait blocks until every goroutine within the current bubble,
|
||||||
// other than the current goroutine, is durably blocked.
|
// other than the current goroutine, is durably blocked.
|
||||||
|
|
|
||||||
|
|
@ -1851,7 +1851,8 @@ func tRunner(t *T, fn func(t *T)) {
|
||||||
t.Logf("cleanup panicked with %v", r)
|
t.Logf("cleanup panicked with %v", r)
|
||||||
}
|
}
|
||||||
// Flush the output log up to the root before dying.
|
// Flush the output log up to the root before dying.
|
||||||
for root := &t.common; root.parent != nil; root = root.parent {
|
// Skip this if this *T is a synctest bubble, because we're not a subtest.
|
||||||
|
for root := &t.common; !root.isSynctest && root.parent != nil; root = root.parent {
|
||||||
root.mu.Lock()
|
root.mu.Lock()
|
||||||
root.duration += highPrecisionTimeSince(root.start)
|
root.duration += highPrecisionTimeSince(root.start)
|
||||||
d := root.duration
|
d := root.duration
|
||||||
|
|
@ -2013,7 +2014,7 @@ func (t *T) Run(name string, f func(t *T)) bool {
|
||||||
// It is called by synctest.Test, from within an already-created bubble.
|
// It is called by synctest.Test, from within an already-created bubble.
|
||||||
//
|
//
|
||||||
//go:linkname testingSynctestTest testing/synctest.testingSynctestTest
|
//go:linkname testingSynctestTest testing/synctest.testingSynctestTest
|
||||||
func testingSynctestTest(t *T, f func(*T)) {
|
func testingSynctestTest(t *T, f func(*T)) (ok bool) {
|
||||||
if t.cleanupStarted.Load() {
|
if t.cleanupStarted.Load() {
|
||||||
panic("testing: synctest.Run called during t.Cleanup")
|
panic("testing: synctest.Run called during t.Cleanup")
|
||||||
}
|
}
|
||||||
|
|
@ -2044,6 +2045,7 @@ func testingSynctestTest(t *T, f func(*T)) {
|
||||||
// parent tests by one of the subtests. Continue aborting up the chain.
|
// parent tests by one of the subtests. Continue aborting up the chain.
|
||||||
runtime.Goexit()
|
runtime.Goexit()
|
||||||
}
|
}
|
||||||
|
return !t2.failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deadline reports the time at which the test binary will have
|
// Deadline reports the time at which the test binary will have
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue