evOo-local/packages/adapters/src/job-reconciler.postgres.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

29 lines
1.1 KiB
TypeScript

import { Pool } from "pg";
import { describe, expect, it } from "vitest";
import { createPostgresReconciliationLeadership } from "./job-reconciler.js";
const databaseUrl = process.env.DATABASE_URL;
const describePostgres =
process.env.VERIFY_DATABASE && databaseUrl ? describe.sequential : describe.skip;
describePostgres("job reconciliation leadership (PostgreSQL contract)", () => {
it("elects one session and hands leadership to a follower after release", async () => {
const pool = new Pool({ connectionString: databaseUrl!, max: 2 });
const lockId = -Math.min(process.pid, 2_000_000_000);
const first = createPostgresReconciliationLeadership(pool, { lockId });
const second = createPostgresReconciliationLeadership(pool, { lockId });
try {
await expect(first.tryAcquire()).resolves.toBe(true);
await expect(second.tryAcquire()).resolves.toBe(false);
await first.release();
await expect(second.tryAcquire()).resolves.toBe(true);
} finally {
await first.release();
await second.release();
await pool.end();
}
});
});