diff --git a/internal/sessions/cursor_snapshot_test.go b/internal/sessions/cursor_snapshot_test.go index bf65d9219..a1a29c8b3 100644 --- a/internal/sessions/cursor_snapshot_test.go +++ b/internal/sessions/cursor_snapshot_test.go @@ -24,9 +24,20 @@ func cursorTempCopies(t *testing.T) []string { func TestCursorEditorCopiedOncePerChange(t *testing.T) { cursorSetup(t) t.Setenv("TMPDIR", t.TempDir()) + // The copy lingers past any pause a loaded runner makes between two + // reads while copies are counted (a 100ms linger let a slow runner drop + // it between List and the next visit, and count a third copy); it is + // cut short only to see the last one removed. The timers read the + // linger under cursorSnaps' lock, so it is set under it. + linger := func(d time.Duration) { + cursorSnaps.Lock() + cursorSnapLinger = d + cursorSnaps.Unlock() + } minWas, lingerWas := cursorSnapMin, cursorSnapLinger - cursorSnapMin, cursorSnapLinger = 0, 100*time.Millisecond - t.Cleanup(func() { cursorSnapMin, cursorSnapLinger = minWas, lingerWas }) + cursorSnapMin = 0 + linger(time.Hour) + t.Cleanup(func() { cursorSnapMin = minWas; linger(lingerWas) }) config, err := os.UserConfigDir() if err != nil { @@ -99,6 +110,10 @@ func TestCursorEditorCopiedOncePerChange(t *testing.T) { t.Fatalf("copies after one change: %d, want 2", n) } + // one more read lets the copy go with a short linger + linger(100 * time.Millisecond) + List(All) + deadline := time.Now().Add(5 * time.Second) for len(cursorTempCopies(t)) > 0 { if time.Now().After(deadline) {