aboutsummaryrefslogtreecommitdiff
path: root/src/testing/synctest
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-05-20 15:56:43 -0700
committerGopher Robot <gobot@golang.org>2025-05-29 10:26:00 -0700
commitb170c7e94c478e616d194af95caa7747d9fa4725 (patch)
treeb77064b4707cc99d60d3727ba62a8fbc1a16ee25 /src/testing/synctest
parent3b77085b40bf0d53528d6852d07c00c81021c855 (diff)
downloadgo-b170c7e94c478e616d194af95caa7747d9fa4725.tar.xz
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 <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/testing/synctest')
-rw-r--r--src/testing/synctest/synctest.go15
1 files changed, 13 insertions, 2 deletions
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.