Skip to content

test: run hold-confirm tests concurrently so the file clears its timeout - #143

Merged
prekabreki merged 1 commit into
mainfrom
fm/ff-holdconfirm-140
Nov 19, 2026
Merged

prekabreki merged 1 commit into
mainfrom
fm/ff-holdconfirm-140

Conversation

@prekabreki

Copy link
Copy Markdown
Owner

Closes #140

What changed

hold-confirm.test.mjs took ~15 s because its tests run one after another, each waiting in real time (HOLD_MS 700, KEYARM_MS 4000).
node --test applies --test-timeout=20000 to each whole file, so only ~4 s of headroom was left.
Every test already builds its own jsdom page, so the tests share no timer state.
They now sit under one describe('hold-to-confirm', { concurrency: true }), and the file costs only its longest wait.
No assertion, wait or constant changed: git diff -w is the import, the wrapper and a comment explaining it.
HOLD_MS stays 700, in step with the page constant and CSS fill.
The timeout in package.json and mutation-check.mjs stays 20000, so the two are still in step.
AGENTS.md's "~15s" for the frontend suite is corrected to "~6s".

Why concurrency is safe here: jsdom's window.setTimeout is Node's setTimeout underneath (timerInitializationSteps in jsdom/browser/Window.js), and the harness sleep() uses that same timer.
So a page timer and the test's check fire in deadline order on one event loop.
A busy loop delays both alike and cannot reorder a hold against the check that follows it.

Verify

node --test tests/frontend/hold-confirm.test.mjs: duration_ms 15168 before, duration_ms 5873 after (19/19 pass).

npm --prefix tests/frontend test:

1..29
# tests 47
# suites 1
# pass 47
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 6115.182931

Stress run: 3 rounds of 6 parallel copies of the file, with all 32 cores pinned by busy loops. 18/18 green, slowest duration_ms 9733 (limit 20000).

npm --prefix tests/frontend run test:mutations:

✓ hold/keyboard-auto-repeat: caught by 2 test(s) — the e.repeat guard on the hold-to-confirm keyboard path
✓ hold/secondary-button: caught by 1 test(s) — the e.button > 0 guard on pointerdown
✓ pr38/playlist-checklist-on-start: caught by 2 test(s) — the playlist branch at the top of startDownload()
✓ pr38/client-owns-overall: caught by 1 test(s) — clientOwnsOverall()
✓ pr38/overall-fraction: caught by 1 test(s) — the completed-items term in renderOverall()
✓ i67/clear-stale-formats: caught by 1 test(s) — clearFormatSelects() on the failed-resolve path of fetchInfo()
✓ i67/show-format-error: caught by 1 test(s) — the info.error log line in fetchInfo()
✓ i130/ytdlp-update-one-line: caught by 2 test(s) — logging the server summary (not the raw output) in updateYtdlp()
✓ 76/range-order: caught by 1 test(s) — the To-after-From check in readSectionFields()
✓ 76/batch-item-range: caught by 1 test(s) — section_start/section_end in toItemPayload()
✓ 76/range-dedupe: caught by 1 test(s) — the range-aware dedupe in addToQueue()
✓ i95/download-http-status: caught by 1 test(s) — the !r.ok check in the shared SSE reader
✓ i98/queue-title-escape: caught by 1 test(s) — the escapeHtml() call around q.title in renderDlQueue()
✓ i95/read-error-retries: caught by 1 test(s) — the non-AbortError branch in the shared SSE reader
✓ i104/no-outcome-fails: caught by 1 test(s) — the no-outcome fallback in the shared SSE reader
✓ i102/typed-encode-params: caught by 1 test(s) — the encode_params branch in handleMsg()
OK — all 16 mutations were caught by the suite.

Danger zone: negative assertions are still load-bearing

The standing mutation check covers only two of this file's guards (e.repeat, e.button).
To prove the time-based "does NOT clear" assertions don't pass vacuously under concurrency, I broke each timer and abort guard in a temporary copy of app.js and ran the concurrent file against it:

caught   orphaned-timer (no clearTimeout on stop, timer fires on captured el) (6.0s): 6/6 expected tests failed; also failed: a plain click does not clear the queue
caught   abort listeners removed (6.0s): 6/6 expected tests failed; also failed: a plain click does not clear the queue
caught   HOLD_MS shortened to 50 (6.0s): 5/5 expected tests failed
caught   HOLD_MS lengthened to 5000 (6.0s): 1/1 expected tests failed
caught   click fires the action (6.0s): 1/1 expected tests failed
caught   arm never expires (6.0s): 1/1 expected tests failed

"orphaned-timer" removes clearTimeout from _holdStop and lets the timer fire on the captured element.
"also failed" means a test outside the expected list also caught it.

Also green: python -m unittest discover -s tests (377 OK, 1 skipped), -s tools/tests (14 OK), ruff check fetchforge tests tools.
The Windows CI frontend step is verified by this PR's own test (windows-latest, …) runs.

hold-confirm.test.mjs is built from real-time waits (HOLD_MS 700,
KEYARM_MS 4000) and took ~15 s run one test after another, against a
20 s --test-timeout that node --test applies to the whole file. A slow
Windows runner ate the remaining headroom and turned main red.

Each test builds its own jsdom page, so the tests share no timer state.
Grouping them under one concurrent describe() leaves every assertion
and wait as it was, and the file now costs only its longest wait:
5.9 s locally, under 10 s with every core busy.

Closes #140
@prekabreki
prekabreki merged commit 6594886 into main Nov 19, 2026
8 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.

Stop hold-confirm.test.mjs timing out on slow Windows CI runners

1 participant