test: settle 202 jobs instead of returning without asserting (#652)

A 202 means the sync window expired while the job was still running. Tests treated it as a terminal pass: `if (isAsyncFallback(res)) return;` checked the envelope and returned, asserting nothing about the outcome and leaving the job running into the next test, which is the leak cancelAcceptedJobAndWait exists to prevent.

Because the window only expires under load, coverage tracked runner load. On CI 44 tests took this path and verified nothing; the same tests on a dev machine asserted in full (one measured 6.4s locally against 31s on CI).

settleAsyncFallback waits for a terminal state and asserts the job finished, and that a failure carries a message rather than being a crash. A clean failure stays valid, since the exotic-format fixtures are meant to be rejected. All 82 call sites moved over.

per-fork-env no longer floors SYNC_WAIT_MS, so forcing it to 0 drives every request through its 202 path. 570 tests were validated that way and matched their normal-window results exactly.

The 29-34s band dropped from 44 tests (23.4% of test time) to 6 (3.0%). Total test time rose 5.8% and CI wall went 12.8 to 13.1 min: the forks were doing real work during that wait, so this buys determinism, not speed. Per-shard totals unchanged at 9903 tests, 9435 passed, 468 skipped.
This commit is contained in:
SnapOtter
2026-07-27 12:16:48 +08:00
committed by GitHub
parent d9978525fe
commit f1ec3beaf7
15 changed files with 177 additions and 167 deletions
+11 -7
View File
@@ -25,13 +25,17 @@ process.env.BULLMQ_PREFIX = `snapotter_test_${suffix}`;
// Heavy format conversions can exceed the 8s production default under parallel
// test forks; 30s keeps tool routes synchronous (200) in tests while production
// stays at 8s. The constrained docker test image (macOS Docker VM, where Sharp
// and FFmpeg run ~2-3x slower) can request a larger window via SYNC_WAIT_MS;
// honor it rather than clobbering, but never drop below the 30s test floor.
const requestedSyncWait = Number(process.env.SYNC_WAIT_MS);
process.env.SYNC_WAIT_MS = String(
Number.isFinite(requestedSyncWait) && requestedSyncWait > 30000 ? requestedSyncWait : 30000,
);
// stays at 8s.
//
// An explicit SYNC_WAIT_MS is now honored verbatim rather than floored. The
// constrained docker test image (macOS Docker VM, where Sharp and FFmpeg run
// ~2-3x slower) still widens the window, and forcing it *down* (SYNC_WAIT_MS=0)
// drives every tool through its 202 path, which is the only way to exercise
// that branch on a machine fast enough to never hit it naturally.
const requestedSyncWait = process.env.SYNC_WAIT_MS?.trim();
const hasExplicitSyncWait =
Boolean(requestedSyncWait) && Number.isFinite(Number(requestedSyncWait));
process.env.SYNC_WAIT_MS = hasExplicitSyncWait ? (requestedSyncWait as string) : "30000";
const dbName = `snapotter_test_${suffix}`; // pid digits + uuid hex: identifier-safe
const admin = new pg.Client({ connectionString: baseUrl });
await admin.connect();