aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-08-27 10:30:46 +0800
committerGopher Robot <gobot@golang.org>2022-08-29 20:19:15 +0000
commitfd2ac5ef968545e8283e32160fe69a9de1e98842 (patch)
treead09550624a02cda51b34560a78f863b4d73907e /src/testing/testing.go
parentb0144b384318e17b7b4facdbbd2fff3712085eab (diff)
downloadgo-fd2ac5ef968545e8283e32160fe69a9de1e98842.tar.xz
testing: convert common.hasSub to atomic type
Change-Id: I3d8a9b901efabe62f432c06361826f46c78d2605 Reviewed-on: https://go-review.googlesource.com/c/go/+/426080 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 5fd153954d..7148537370 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -539,7 +539,7 @@ type common struct {
chatty *chattyPrinter // A copy of chattyPrinter, if the chatty flag is set.
bench bool // Whether the current test is a benchmark.
- hasSub int32 // Written atomically.
+ hasSub atomic.Bool // whether there are sub-benchmarks.
raceErrors int // Number of races detected during test.
runner string // Function name of tRunner running the test.
@@ -1459,7 +1459,7 @@ func tRunner(t *T, fn func(t *T)) {
// Do not lock t.done to allow race detector to detect race in case
// the user does not appropriately synchronize a goroutine.
t.done = true
- if t.parent != nil && atomic.LoadInt32(&t.hasSub) == 0 {
+ if t.parent != nil && !t.hasSub.Load() {
t.setRan()
}
}()
@@ -1486,7 +1486,7 @@ func tRunner(t *T, fn func(t *T)) {
// Run may be called simultaneously from multiple goroutines, but all such calls
// must return before the outer test function for t returns.
func (t *T) Run(name string, f func(t *T)) bool {
- atomic.StoreInt32(&t.hasSub, 1)
+ t.hasSub.Store(true)
testName, ok, _ := t.context.match.fullName(&t.common, name)
if !ok || shouldFailFast() {
return true