test(server): settle credential cleanup without clock overshoot

Wait for real SQL before advancing to an actually scheduled coalescing follow-up, preserving the intermediate future-expiry assertions.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-27 00:57:59 -05:00
1 parent 7436d29cc9
commit bc66ea0054
2 files changed
+16 -2

No files matched your search

+7
View File
@@ -111,3 +111,10 @@ behavioral evidence; combined-stack and fresh remote checks remain required.
The full local test:run remains unverified because of embedded PostgreSQL
startup/capacity limits; the two real gateway suites used separate migrated,
task-owned disposable PostgreSQL databases.
A later combined run exposed a test-clock overshoot: repeated blind 30-second
advances could expire the future session before its intermediate assertion.
The settlement helper now lets real SQL settle and advances only to an actually
armed follow-up within the coalescing window. All 12 credential expiry tests pass
on the owning gateway branch with the existing exact-deadline and transaction
assertions intact. This follow-up changes the test fixture only.
@@ -60,8 +60,15 @@ describe.skipIf(!supported)("gateway credential expiry", () => {
async function settle(ms = 60_000) {
await vi.advanceTimersByTimeAsync(ms);
if (!draining) await vi.waitFor(async () => {
// SQL may finish after the clock jump and arm a coalesced follow-up pass.
if (idleWorkSnapshot().active > 0) await vi.advanceTimersByTimeAsync(30_000);
// Let real SQL settle before advancing only to an actually armed follow-up.
// Repeated blind clock jumps can expire the future credential under test.
if (idleWorkSnapshot().active > 0) {
await db.execute(sql`select pg_sleep(0.01)`);
const next = coordinator!.nextWakeAt();
if (next !== null && next <= Date.now() + 30_000) {
await vi.advanceTimersByTimeAsync(Math.max(0, next - Date.now()));
}
}
expect(idleWorkSnapshot().active).toBe(0);
}, { timeout: 5000 });
}