From 001b1dbf77519920374af035bac43c483fe8635b Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 30 Oct 2026 22:05:27 -0500 Subject: [PATCH] test(github): isolate scheduler time from postgres housekeeping Fast virtual-time advances could expire a real connection before socket I/O and retain a correct retry hold. Disable driver housekeeping only in this fixture and assert the scoped worker reports no errors. Co-Authored-By: Paperclip --- server/src/__tests__/github-connection-work.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/src/__tests__/github-connection-work.test.ts b/server/src/__tests__/github-connection-work.test.ts index 783ed45de43..de620d3f7b5 100644 --- a/server/src/__tests__/github-connection-work.test.ts +++ b/server/src/__tests__/github-connection-work.test.ts @@ -44,7 +44,11 @@ describeDatabase("GitHub coordinator with PostgreSQL and controlled Cloud HTTP ( beforeAll(async () => { if (databaseUrl) await applyPendingMigrations(databaseUrl); else temporaryDatabase = await startEmbeddedPostgresTestDatabase("paperclip-github-work-"); - db = createDb(databaseUrl ?? temporaryDatabase!.connectionString, { maxConnections: 4 }); + // Only scheduler time is virtual here. Driver housekeeping must not expire + // a real socket connection while that fake clock advances across idle windows. + db = createDb(databaseUrl ?? temporaryDatabase!.connectionString, { + maxConnections: 4, idleTimeoutSeconds: 0, connectTimeoutSeconds: 0, maxLifetimeSeconds: 0, + }); // This explicitly assigned external test database is exclusive to this suite. await db.transaction(async tx => { await tx.execute(sql`SET LOCAL client_min_messages = warning`); await tx.execute(sql`TRUNCATE companies CASCADE`); }); server = createServer(async (req, res) => { @@ -409,7 +413,8 @@ describeDatabase("GitHub coordinator with PostgreSQL and controlled Cloud HTTP ( const schedule = f.service.githubConnectionContinuitySchedule.bind(f.service); const load = vi.spyOn(f.service, "githubConnectionContinuitySchedule").mockImplementation(companyId => { loadTimes.push(Date.now()); return schedule(companyId); }); const sweep = vi.spyOn(f.service, "sweepGitHubConnectionContinuity"); - const coordinator = createDeliveryWorkCoordinator({ owner: db, canRun: () => true }); + const errors: unknown[] = []; + const coordinator = createDeliveryWorkCoordinator({ owner: db, canRun: () => true, onError: error => errors.push(error) }); const continuity = registerGitHubConnectionContinuityWork(db, coordinator, f.service, () => true); const events = registerGitHubConnectionEventWork(db, coordinator, githubConnectionEventService(db, { connector: f.connector }), () => true); try { @@ -423,6 +428,7 @@ describeDatabase("GitHub coordinator with PostgreSQL and controlled Cloud HTTP ( } await vi.advanceTimersByTimeAsync(10_000); expect(load).not.toHaveBeenCalled(); expect(sweep).not.toHaveBeenCalled(); expect(leases).toBe(1); + expect(errors).toEqual([]); for (let index = 0; index < 30; index++) await db.transaction(async tx => { await notifyGitHubCredentialChange(tx, f.connection); }); expect(leases).toBeLessThanOrEqual(2); await vi.advanceTimersByTimeAsync(6_000); @@ -442,6 +448,7 @@ describeDatabase("GitHub coordinator with PostgreSQL and controlled Cloud HTTP ( const quiet = { leases, loads: load.mock.calls.length }; await vi.advanceTimersByTimeAsync(60_000); expect({ leases, loads: load.mock.calls.length }).toEqual(quiet); + expect(errors).toEqual([]); } finally { await events.stop(); await continuity.stop(); await coordinator.stop(); } });