mirror of
https://github.com/golang/go
synced 2024-11-22 14:04:48 -07:00
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>
This commit is contained in:
parent
b0144b3843
commit
fd2ac5ef96
@ -242,7 +242,7 @@ func (b *B) run1() bool {
|
||||
b.mu.RLock()
|
||||
finished := b.finished
|
||||
b.mu.RUnlock()
|
||||
if atomic.LoadInt32(&b.hasSub) != 0 || finished {
|
||||
if b.hasSub.Load() || finished {
|
||||
tag := "BENCH"
|
||||
if b.skipped {
|
||||
tag = "SKIP"
|
||||
@ -639,7 +639,7 @@ var hideStdoutForTesting = false
|
||||
func (b *B) Run(name string, f func(b *B)) bool {
|
||||
// Since b has subbenchmarks, we will no longer run it as a benchmark itself.
|
||||
// Release the lock and acquire it on exit to ensure locks stay paired.
|
||||
atomic.StoreInt32(&b.hasSub, 1)
|
||||
b.hasSub.Store(true)
|
||||
benchmarkLock.Unlock()
|
||||
defer benchmarkLock.Lock()
|
||||
|
||||
@ -671,7 +671,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
|
||||
if partial {
|
||||
// Partial name match, like -bench=X/Y matching BenchmarkX.
|
||||
// Only process sub-benchmarks, if any.
|
||||
atomic.StoreInt32(&sub.hasSub, 1)
|
||||
sub.hasSub.Store(true)
|
||||
}
|
||||
|
||||
if b.chatty != nil {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user