| 123456789101112131415161718192021222324 |
- import assert from 'node:assert/strict';
- import test from 'node:test';
- import type { Pool } from 'pg';
- import { recoverStaleSyncJobs } from '../src/modules/domestic-voc/jobs/sync-worker.js';
- test('stale processing jobs are recovered with a bounded age threshold', async () => {
- let sql = '';
- let values: readonly unknown[] | undefined;
- const pool = {
- async query(text: string, input?: readonly unknown[]) {
- sql = text;
- values = input;
- return { rows: [{ recovered_count: 2 }], rowCount: 1 };
- },
- } as unknown as Pool;
- const recovered = await recoverStaleSyncJobs(pool, 900_000);
- assert.equal(recovered, 2);
- assert.deepEqual(values, [900_000]);
- assert.match(sql, /status = 'processing'/);
- assert.match(sql, /attempts < max_attempts/);
- assert.match(sql, /sync_stale_recovered/);
- });
|