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