Repository navigation
test(helpers): share one bounded waiter and Postgres lock-wait probe across tests - #3165
Merged
Merged
Conversation
…iter
Extend tests/helpers/wait-for.mjs with an options form ({ timeoutMs, intervalMs }),
a lazily built description and waitUntil for boolean checks, and add
tests/helpers/postgres-lock-waits.mjs for the pg_blocking_pids probes that
lock-order tests copied into each file. Migrate the hand-rolled deadline loops
in checks and Postgres test files onto them; three unbounded 'while (!release)'
loops become bounded.
Treat an empty pid file as not yet written in plugin-driver, word the processGone description as the awaited outcome, document why the lock-wait helper needs no wait_event_type filter and which waiter it returns, accept a null options argument, and keep helper imports after the app imports.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
runtime-image-native-worker copies this file and available-port.mjs into the runtime image and runs it there, so it cannot import the shared waiter without that test also shipping wait-for.mjs (Image Runtime Startup 3 failed on 1cbfe12). Restore the file; its four loops stay listed in the survey.
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Integration and conformance tests copy the same polling code into each file:
const deadline = Date.now() + N; while (...) { assert.ok(Date.now() < deadline, ...); await delay(M); }. A survey oftests/integration/andtests/conformance/found 66 hand-rolled wait loops. Three of them (while (!release) await delay(10)) had no deadline at all. Lock-order tests also copied the samepg_blocking_pidsprobe ("wait until a backend waits on this lock") into 8 files, 11 times.tests/helpers/wait-for.mjsalready had a boundedwaitFor, but its fixed 20 ms interval and string-only description kept most callers hand-rolling their own loops.Survey top (copies x lines, of what this PR addresses):
ci-runner.test.mjs,workspace-node-supervisorwhich runs inside the runtime image, intentional fixed-duration probes)pg_blocking_pidslock-wait probesThe full survey, including clusters left for later, is kept outside the repository.
Change
tests/helpers/wait-for.mjs:waitFor(description, read, timeoutMs | { timeoutMs, intervalMs }). The description can be a function that runs at the deadline, so a timeout reports the state still wrong (backend pids, child output). NewwaitUntilfor boolean checks. Existing callers are unchanged.tests/helpers/postgres-lock-waits.mjs:waitForLockWaiter(pool, holderPid, description, { count, queryLike, ...})andwaitForLockHolder(pool, waiterPid, description, ...).postgres-namespace-lock.mjsnow uses it.pserrors) and cleanup on timeout (the held provider responses inrepository-credentials-descriptions). The three unboundedwhile (!release)loops are now bounded.tests/conformance/workspace-node-supervisor.test.mjsstays self-contained:runtime-image-native-workercopies it into the runtime image with onlyavailable-port.mjs, so it cannot import the waiter (its first migration failed Image Runtime Startup 3 on 1cbfe12 and was reverted in fc85bdf).Verification
All runs on a remote test VM, on f4b810c unless noted. 1cbfe12 adds only review nits, fc85bdf restores workspace-node-supervisor, and c298ff5 merges main:
uncertain: 0: 3 cases inrepository-credentials-service-loss.pending: 8 cases inrepository-credentials-descriptions.lockNamespacewithoutFOR UPDATE: 3 postgres-agent-provisioning Stop/handoff lock-order cases.findServiceAccountwithout its row lock: the service-account-deletion forced-delete case and the service-account-issuance-recovery reclaim case.--max-warnings 0and prettier on the touched files.Open PRs touching these files (#115, #906, #1557, #1707, #2258, #2259, #2268, #2398, #2445, #2633, #2982):
git merge-treeagainst this head gives the same conflicted files as against main. No new conflicts.Risks
Low; test-only. Failure messages change wording ("Timed out waiting for ."). A few deadlines changed shape. Two descriptions waits that shared one 5 s deadline now get 5 s each. A 300 x 10 ms attempt loop is now a 5 s deadline. One workspace-node-supervisor retry wait polls every 25 ms instead of 50 ms. Real Docker/k3d files were not migrated because they could not be proven here. They are listed in the survey for a follow-up, along with a
retryErrorsoption theirwaitForcopies would need.