mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
Two regression nets for the W-POOL changes shipped in the prior two commits: * `src/lib/__tests__/db.test.ts` — assert `getPoolMax()` returns 20 by default and honours `DATABASE_POOL_MAX`, with a final assertion that pins the floor at 20 so a future refactor that drops the explicit `max:` config can't silently revert to the library default of 10. * `src/app/api/analytics/__tests__/route.test.ts` — instrument the per-type `findMany` mock with inflight counters and assert peak concurrency never exceeds `ANALYTICS_TYPE_FETCH_CONCURRENCY`. The wall-clock window also catches both an unbounded `Promise.all` regression (would finish too fast) and an accidental serialisation (would finish too slow).
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
/**
|
|
* v1.4.40 W-POOL — pool-config contract for `src/lib/db.ts`.
|
|
*
|
|
* The v1.4.39 empirical cold-mount trace
|
|
* (`.planning/round-v1439-empirical-trace.md` § B2) traced the
|
|
* Wave-B/C dashboard-query stall to the Prisma `pg.Pool` falling
|
|
* back to the library default ceiling of 10 connections. W-POOL
|
|
* pinned the ceiling to 20 via `getPoolMax()`; this test prevents a
|
|
* future refactor from silently dropping the override and re-introducing
|
|
* the saturation regression on a power-user cold mount.
|
|
*
|
|
* The test only exercises the `getPoolMax()` env-resolver. Constructing
|
|
* a real `PrismaClient` requires a live `DATABASE_URL`, which would
|
|
* make this an integration test instead of a unit test — the helper
|
|
* isolation is intentional.
|
|
*/
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
|
|
import { getPoolMax } from "../db";
|
|
|
|
describe("getPoolMax", () => {
|
|
const originalEnv = process.env.DATABASE_POOL_MAX;
|
|
|
|
beforeEach(() => {
|
|
delete process.env.DATABASE_POOL_MAX;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (originalEnv === undefined) {
|
|
delete process.env.DATABASE_POOL_MAX;
|
|
} else {
|
|
process.env.DATABASE_POOL_MAX = originalEnv;
|
|
}
|
|
});
|
|
|
|
it("defaults to 20 when DATABASE_POOL_MAX is unset", () => {
|
|
expect(getPoolMax()).toBe(20);
|
|
});
|
|
|
|
it("honours DATABASE_POOL_MAX when it parses to a positive int", () => {
|
|
process.env.DATABASE_POOL_MAX = "30";
|
|
expect(getPoolMax()).toBe(30);
|
|
});
|
|
|
|
it("falls back to 20 on a malformed DATABASE_POOL_MAX", () => {
|
|
process.env.DATABASE_POOL_MAX = "not-a-number";
|
|
expect(getPoolMax()).toBe(20);
|
|
});
|
|
|
|
it("falls back to 20 on a non-positive DATABASE_POOL_MAX", () => {
|
|
process.env.DATABASE_POOL_MAX = "0";
|
|
expect(getPoolMax()).toBe(20);
|
|
process.env.DATABASE_POOL_MAX = "-5";
|
|
expect(getPoolMax()).toBe(20);
|
|
});
|
|
|
|
it("never returns the library default of 10 on the happy path", () => {
|
|
// The whole point of the W-POOL change. If anybody removes the
|
|
// `max:` config from `createPrismaClient` and reverts to the
|
|
// library default, this assertion stops the regression before the
|
|
// next saturated cold mount.
|
|
expect(getPoolMax()).toBeGreaterThanOrEqual(20);
|
|
});
|
|
});
|