Skip to content

Commit 470d1ad

Browse files
committed
test(driver-sql): track the black-hole query's settlement explicitly so a resolved query is not read as pending
The stepping loop stopped on a captured rejection only, so a query that RESOLVED (the "should have failed" case) would have been misreported as "still pending after 20s". Settlement is now one of two named outcomes, and each has its own assertion message. Claude-Session: https://claude.ai/code/session_01ADzJtzYTLUfgrRZHxkagkX Co-authored-by: Claude <noreply@anthropic.com>
1 parent aebdcaf commit 470d1ad

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎packages/drivers/driver-sql/src/sql-driver-connect-bound.test.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ describe('SqlDriver — connection-attempt bound (framework#3769)', () => {
227227
connection: `postgres://u:p@127.0.0.1:${port}/d`,
228228
pool: { min: 0, max: 2 },
229229
});
230-
let err: Error | undefined;
231-
const outcome = (d as any).knex.raw('SELECT 1').then(
232-
() => { throw new Error('query resolved but should have failed'); },
233-
(e: Error) => { err = e; },
230+
let settled = undefined as { ok: true } | { ok: false; error: Error } | undefined;
231+
(d as any).knex.raw('SELECT 1').then(
232+
() => { settled = { ok: true }; },
233+
(error: Error) => { settled = { ok: false, error }; },
234234
);
235235

236236
// Real I/O: do not move the clock until the server holds the socket, so
@@ -242,20 +242,21 @@ describe('SqlDriver — connection-attempt bound (framework#3769)', () => {
242242
// Each step also lets a real macrotask run, so the socket teardown and
243243
// the rejection it causes land before the next step is judged.
244244
let elapsed = 0;
245-
while (err === undefined && elapsed < 20_000) {
245+
while (settled === undefined && elapsed < 20_000) {
246246
await vi.advanceTimersByTimeAsync(500);
247247
await new Promise<void>((resolve) => setImmediate(resolve));
248248
elapsed += 500;
249249
}
250-
expect(err, 'still pending after 20s of fake time — the connect is unbounded').toBeDefined();
251-
await outcome; // surfaces the "resolved but should have failed" throw, if any
250+
expect(settled, 'still pending after 20s of fake time — the connect is unbounded').toBeDefined();
251+
expect(settled?.ok, 'query resolved but should have failed').toBe(false);
252+
const err = (settled as { ok: false; error: Error }).error;
252253

253254
// The pg-level timeout fires first (10s), so the message names the
254255
// connection attempt rather than blaming pool sizing. Guarding against
255256
// the regression is the point: knex's own wording would send an operator
256257
// to tune `pool.max` while the network is what is broken.
257-
expect(err!.message).toContain('timeout expired');
258-
expect(err!.message).not.toContain('pool is probably full');
258+
expect(err.message).toContain('timeout expired');
259+
expect(err.message).not.toContain('pool is probably full');
259260
expect(elapsed).toBeGreaterThan(8_000);
260261
expect(elapsed).toBeLessThan(20_000);
261262
} finally {

0 commit comments

Comments
 (0)