Overlays: review r1 fixes (lifecycle goroutine settle)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 13:04:19 -04:00
1 parent 7a0d304fa4
commit 0e5a03707a
1 file changed
+13 -1
+13 -1
View File
@@ -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