Skip to content

test: replace fixed time.Sleep with poll-until-ready in tmux tests#73

Merged
tzone85 merged 1 commit into
mainfrom
fix/tmux-sendkeys-flake
Jun 12, 2026
Merged

test: replace fixed time.Sleep with poll-until-ready in tmux tests#73
tzone85 merged 1 commit into
mainfrom
fix/tmux-sendkeys-flake

Conversation

@tzone85

@tzone85 tzone85 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

`TestSendKeysRaw`, `TestSendKeysRaw_ThenEnter`, and `TestSendKeysAndCapture` captured the tmux pane after a fixed 500ms warmup + 300-500ms post-send sleep. Under CI load the `echo` hadn't completed before capture, so the assertion failed intermittently.

Fix

New helpers in `internal/tmux/send_test.go`:

  • `waitForPaneReady` — polls until the pane shows any prompt-like text (session is up).
  • `waitForPaneContains` — polls until the expected substring appears.

Both tick every 50ms against a 3-5s deadline. Fast laptops finish in well under the previous 500ms warmup; slow CI shells stretch transparently.

Test plan

  • `go test ./internal/tmux/ -run "TestSendKeysRaw\$|TestSendKeysRaw_ThenEnter" -count=1` x10 — 10/10 pass
  • `go test ./internal/tmux/ -count=1` x5 — 5/5 pass
  • `go test ./... -count=1` — all 30 packages pass

Notes

  • Local wall time: ~2.4s → ~1.6s on a fast machine because the poll finishes before the worst-case fixed sleep.
  • The two `time.Sleep(300ms)` calls in `session_coverage_test.go` are intentionally left — those tests only assert `err == nil` and don't read specific content, so they're not a known flake source. Marginal optimisation, not a correctness change — out of scope.

The TestSendKeysRaw / TestSendKeysRaw_ThenEnter / TestSendKeysAndCapture
tests captured the tmux pane after a fixed 500ms warmup + 300-500ms
post-send sleep. Under CI load (slow shells, contended schedulers) the
echo command hadn't completed before capture, so the assertion failed
intermittently.

New helpers in send_test.go:
- waitForPaneReady polls until the pane shows any prompt-like text
- waitForPaneContains polls until the expected substring appears

Both use 50ms ticks against a 3-5s deadline. Fast laptops finish in
well under 500ms; slow CI shells stretch transparently.

Local wall time: ~2.4s → ~1.6s on a fast machine because the poll
finishes before the worst-case fixed sleep. Ran 10x in a row with
no failures.

CI behaviour: the tests were never the source of a known production
incident — the flake had been tracked in CLAUDE.md as PR-FLAKE since
the lint job re-enable. The fix is preventative.
@tzone85 tzone85 merged commit 5b1704f into main Jun 12, 2026
5 checks passed
tzone85 added a commit that referenced this pull request Jun 16, 2026
The TestSendKeysRaw / TestSendKeysRaw_ThenEnter / TestSendKeysAndCapture
tests captured the tmux pane after a fixed 500ms warmup + 300-500ms
post-send sleep. Under CI load (slow shells, contended schedulers) the
echo command hadn't completed before capture, so the assertion failed
intermittently.

New helpers in send_test.go:
- waitForPaneReady polls until the pane shows any prompt-like text
- waitForPaneContains polls until the expected substring appears

Both use 50ms ticks against a 3-5s deadline. Fast laptops finish in
well under 500ms; slow CI shells stretch transparently.

Local wall time: ~2.4s → ~1.6s on a fast machine because the poll
finishes before the worst-case fixed sleep. Ran 10x in a row with
no failures.

CI behaviour: the tests were never the source of a known production
incident — the flake had been tracked in CLAUDE.md as PR-FLAKE since
the lint job re-enable. The fix is preventative.

Co-authored-by: Thando Mini <tzone85@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant