From 0e5a03707aa76b49d349051cfbe7ca68c1954888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 5 Oct 2026 13:04:19 -0400 Subject: [PATCH] Overlays: review r1 fixes (lifecycle goroutine settle) --- overlay_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/overlay_test.go b/overlay_test.go index 5fa3e8a..f7ad203 100644 --- a/overlay_test.go +++ b/overlay_test.go @@ -261,7 +261,8 @@ func TestOverlayLifecycle(t *testing.T) { if got := len(tt.Texts()); got != texts { t.Errorf("%s: texts %d -> %d", oc.name, texts, got) } - if g := runtime.NumGoroutine(); g > goroutines { + // A fired c.After timer (ui/runtime.go:596) runs briefly in its own goroutine; only lasting growth counts. + if g := overlayGoroutines(goroutines); g > goroutines { t.Errorf("%s: goroutines %d -> %d", oc.name, goroutines, g) } if after := heapObjects(); after > before+2000 { @@ -270,6 +271,17 @@ func TestOverlayLifecycle(t *testing.T) { } } +// overlayGoroutines waits up to 2 s for the goroutine count to fall to want, and returns it. +func overlayGoroutines(want int) int { + end := time.Now().Add(2 * time.Second) + g := runtime.NumGoroutine() + for g > want && time.Now().Before(end) { + time.Sleep(10 * time.Millisecond) + g = runtime.NumGoroutine() + } + return g +} + func heapObjects() uint64 { runtime.GC() var m runtime.MemStats