Skip to content

Fix flaky test_single_query_terminated_with_semicolon - #1175

Merged
tconbeer merged 1 commit into
mainfrom
claude/affectionate-clarke-n4i88p
Oct 1, 2026
Merged

tconbeer merged 1 commit into
mainfrom
claude/affectionate-clarke-n4i88p

Conversation

@tconbeer

@tconbeer tconbeer commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1174

What are the key elements of this solution?

test_single_query_terminated_with_semicolon[sqlite] failed all three Windows retries in this run. The test focused the editor as soon as a results table was mounted. At that point Harlequin.load_tables could still be running, and its trailing results_viewer.focus() took focus back. The next ctrl+j then went to the Results Viewer, which doesn't bind it, so no second QuerySubmitted was posted.

  • Adds wait_for_results(pilot, app, messages, count=n) to tests/functional_tests/helpers.py. It waits for the n-th ResultsFetched, then waits for results_viewer.loading to clear. The message hook fires before the handler runs, and loading clears in the same synchronous tail of load_tables that moves focus to the Results Viewer.
  • In test_single_query_terminated_with_semicolon, uses it in place of wait_for_any_table and the two wait_for_workers calls. The test reads tab_count and moves focus right after those waits.
  • Applies the same change to test_multiple_queries, which has the same wait → editor.focus() → ctrl+j pattern.

Why did you design your solution this way? Did you assess any alternatives? Are there tradeoffs?

It waits on the condition the test actually depends on, rather than a sleep or retry, per tests/waiting.py's conventions. I reproduced the race locally by injecting a 0.3s delay before ResultsFetched is posted and a 0.5s delay after add_pane in push_table. With those delays the old test failed every run with the CI error (timed out … waiting for 2 QuerySubmitted messages, saw 1), and the new test passed every run. The delays were not committed. test_multiple_queries didn't fail under those delays, so that change is preventive.

Does this PR require a change to Harlequin's docs?

  • No.
  • Yes, and I have opened a PR at tconbeer/harlequin-web.
  • Yes; I haven't opened a PR, but the gist of the change is: ...

Did you add or update tests for this change?

  • Yes.
  • No, I believe tests aren't necessary.
  • No, I need help with testing this change.

Please complete the following checklist:

  • I have added an entry to CHANGELOG.md, under the [Unreleased] section heading. That entry references the issue closed by this PR. — Not added: test-only change, nothing user-facing.
  • I acknowledge Harlequin's MIT license. I do not own my contribution.

Locally: pytest -m "not online" 2131 passed; ruff, mypy, and lint-imports clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_016SvJmAXqxMtxPYcygLwinH


Generated by Claude Code

tconbeer commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Windows-latest - 3.10 (job) failed during dependency install, before any test ran. uv couldn't fetch the pinned pytest-textual-snapshot git dependency (fatal: unable to access 'https://github.com/tconbeer/pytest-textual-snapshot.git/': Empty reply from server). This is a network error, not caused by this PR, and there is no fix to port. I'll re-run the failed job once, after the workflow run finishes (GitHub refuses a re-run while the run is in progress).


Generated by Claude Code

The test focused the editor as soon as a results table was mounted, while
load_tables was still running; its later results_viewer.focus() took focus
back, so the next ctrl+j landed on the Results Viewer and submitted nothing.

Add wait_for_results, which waits for ResultsFetched and for the Results
Viewer to stop loading, and use it wherever the test moves focus or reads
tab_count after a query. test_multiple_queries had the same pattern.

Closes #1174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016SvJmAXqxMtxPYcygLwinH
@tconbeer
tconbeer force-pushed the claude/affectionate-clarke-n4i88p branch from 7085322 to fb03fb4 Compare October 1, 2026 19:29
@tconbeer
tconbeer merged commit 25323fa into main Oct 1, 2026
32 checks passed
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.

Flaky test: test_single_query_terminated_with_semicolon[sqlite] loses its second Ctrl+J

2 participants