diff options
| author | cuiweixie <cuiweixie@gmail.com> | 2022-09-02 10:44:46 +0800 |
|---|---|---|
| committer | Daniel Martí <mvdan@mvdan.cc> | 2022-09-05 08:08:18 +0000 |
| commit | 4ad55cd93f212eb90324ccafe5b492e404bd5e48 (patch) | |
| tree | c932189bd236d3bfd0fa38a49355edb5cbf01e31 /src/runtime/stack_test.go | |
| parent | 02700e55a57647c837618d713102c8f8214657d8 (diff) | |
| download | go-4ad55cd93f212eb90324ccafe5b492e404bd5e48.tar.xz | |
runtime: convert local var started,progress at TestStackGrowth to atomic type
For #53821
Change-Id: I9c777ff642ea4b70073335279551cea6a2394569
Reviewed-on: https://go-review.googlesource.com/c/go/+/427138
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Diffstat (limited to 'src/runtime/stack_test.go')
| -rw-r--r-- | src/runtime/stack_test.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go index dfb29a99bc..fe73a6362a 100644 --- a/src/runtime/stack_test.go +++ b/src/runtime/stack_test.go @@ -109,13 +109,14 @@ func TestStackGrowth(t *testing.T) { // in finalizer var finalizerStart time.Time - var started, progress uint32 + var started atomic.Bool + var progress atomic.Uint32 wg.Add(1) s := new(string) // Must be of a type that avoids the tiny allocator, or else the finalizer might not run. SetFinalizer(s, func(ss *string) { defer wg.Done() finalizerStart = time.Now() - atomic.StoreUint32(&started, 1) + started.Store(true) growStack(&progress) }) setFinalizerTime := time.Now() @@ -128,10 +129,10 @@ func TestStackGrowth(t *testing.T) { // Panic — instead of calling t.Error and returning from the test — so // that we get a useful goroutine dump if the test times out, especially // if GOTRACEBACK=system or GOTRACEBACK=crash is set. - if atomic.LoadUint32(&started) == 0 { + if !started.Load() { panic("finalizer did not start") } else { - panic(fmt.Sprintf("finalizer started %s ago (%s after registration) and ran %d iterations, but did not return", time.Since(finalizerStart), finalizerStart.Sub(setFinalizerTime), atomic.LoadUint32(&progress))) + panic(fmt.Sprintf("finalizer started %s ago (%s after registration) and ran %d iterations, but did not return", time.Since(finalizerStart), finalizerStart.Sub(setFinalizerTime), progress.Load())) } }) defer timer.Stop() @@ -139,7 +140,7 @@ func TestStackGrowth(t *testing.T) { GC() wg.Wait() - t.Logf("finalizer started after %s and ran %d iterations in %v", finalizerStart.Sub(setFinalizerTime), atomic.LoadUint32(&progress), time.Since(finalizerStart)) + t.Logf("finalizer started after %s and ran %d iterations in %v", finalizerStart.Sub(setFinalizerTime), progress.Load(), time.Since(finalizerStart)) } // ... and in init @@ -147,7 +148,7 @@ func TestStackGrowth(t *testing.T) { // growStack() //} -func growStack(progress *uint32) { +func growStack(progress *atomic.Uint32) { n := 1 << 10 if testing.Short() { n = 1 << 8 @@ -159,7 +160,7 @@ func growStack(progress *uint32) { panic("stack is corrupted") } if progress != nil { - atomic.StoreUint32(progress, uint32(i)) + progress.Store(uint32(i)) } } GC() |
