sync-worker.test.ts 828 B

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