From b170c7e94c478e616d194af95caa7747d9fa4725 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 20 May 2025 15:56:43 -0700 Subject: runtime, internal/synctest, sync: associate WaitGroups with bubbles Add support to internal/synctest for managing associations between arbitrary pointers and synctest bubbles. (Implemented internally to the runtime package by attaching a special to the pointer.) Associate WaitGroups with bubbles. Since WaitGroups don't have a constructor, perform the association when Add is called. All Add calls must be made from within the same bubble, or outside any bubble. When a bubbled goroutine calls WaitGroup.Wait, the wait is durably blocking iff the WaitGroup is associated with the current bubble. Change-Id: I77e2701e734ac2fa2b32b28d5b0c853b7b2825c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/676656 Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil --- src/testing/synctest/synctest.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/testing') diff --git a/src/testing/synctest/synctest.go b/src/testing/synctest/synctest.go index c7e93b2201..1664cb8484 100644 --- a/src/testing/synctest/synctest.go +++ b/src/testing/synctest/synctest.go @@ -72,10 +72,17 @@ // - a blocking select statement where every case is a channel created // within the bubble // - [sync.Cond.Wait] -// - [sync.WaitGroup.Wait] +// - [sync.WaitGroup.Wait], when [sync.WaitGroup.Add] was called within the bubble // - [time.Sleep] // -// Locking a [sync.Mutex] or [sync.RWMutex] is not durably blocking. +// Operations not in the above list are not durably blocking. +// In particular, the following operations may block a goroutine, +// but are not durably blocking because the goroutine can be unblocked +// by an event occurring outside its bubble: +// +// - locking a [sync.Mutex] or [sync.RWMutex] +// - blocking on I/O, such as reading from a network socket +// - system calls // // # Isolation // @@ -83,6 +90,10 @@ // is associated with it. Operating on a bubbled channel, timer, or // ticker from outside the bubble panics. // +// A [sync.WaitGroup] becomes associated with a bubble on the first +// call to Add or Go. Once a WaitGroup is associated with a bubble, +// calling Add or Go from outside that bubble panics. +// // Cleanup functions and finalizers registered with // [runtime.AddCleanup] and [runtime.SetFinalizer] // run outside of any bubble. -- cgit v1.3-5-g9baa