From 2efb71ea0f13db8c93ce3fa286718239c96217ec Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 00:03:18 +0800 Subject: [PATCH] tests: TestCursorEditorCopiedOncePerChange keeps its copy past a loaded runner's pause, not a 100ms linger that counts a third copy The test set cursorSnapLinger to 100ms for the whole run, so a pause of more than that between two reads (List after the change, then the next visit) let the shared copy go and the next read made another: "copies after one change: 3, want 2" in a go test -tags nogui ./... run on a Mac at load average ~200. The linger is now an hour while copies are counted and cut to 100ms only for the last check, that nothing is left in the temp folder. It is set under cursorSnaps' lock, where the timers read it. Run: with a 300ms sleep injected before the visit after the change, the old test fails with "copies after one change: 3, want 2"; the new one passes with 300ms sleeps injected there and between the first two visits. go test -race -count=5 of it and TestCursorLeftCopiesSwept; go test -tags nogui ./internal/sessions (whole package, sandbox HOME); gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows. --- internal/sessions/cursor_snapshot_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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) {