mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-07 04:12:04 +00:00
test(integration): seed the large pulse account a month at a time
The heap test for the pulse day-mean rebuild wrote its million readings in one INSERT ... SELECT, which outran the 60-second statement timeout on CI's shared Postgres. The fixture is now written a month per statement, each in its own transaction with the timeout lifted for that transaction only, and ANALYZE the same way; the code under test keeps the timeout, and the production-heap assertions are unchanged. With the timeout at 4 seconds the old seed is cancelled with 57014 and the new one passes.
This commit is contained in:
1 parent
294be53883
commit
2844088251
1 file changed
+32
-13
@@ -357,19 +357,38 @@ describe("a large account under the production heap", () => {
|
||||
});
|
||||
// One reading a minute for two years, about a million rows, and every
|
||||
// seventh hour holding a single reading so the two methods disagree.
|
||||
await prisma.$executeRaw`
|
||||
INSERT INTO measurements (id, user_id, type, unit, source, value, measured_at, created_at, updated_at)
|
||||
SELECT 'big-' || g::text, ${BIG}, 'PULSE', 'bpm', 'APPLE_HEALTH',
|
||||
60 + (g % 40),
|
||||
ts, now(), now()
|
||||
FROM generate_series(
|
||||
date_trunc('day', now()) - (${YEARS} * interval '365 days'),
|
||||
date_trunc('day', now()) - interval '1 minute',
|
||||
interval '1 minute'
|
||||
) WITH ORDINALITY AS s(ts, g)
|
||||
WHERE extract(hour FROM ts)::int % 7 <> 3 OR extract(minute FROM ts)::int = 0
|
||||
`;
|
||||
await prisma.$executeRaw`ANALYZE measurements`;
|
||||
//
|
||||
// Written a month at a time, each month in its own transaction with the
|
||||
// statement timeout lifted for that transaction only: as one statement
|
||||
// the million-row insert outran the timeout on CI's shared Postgres, and
|
||||
// the timeout guards the code under test, not this fixture.
|
||||
const end = new Date();
|
||||
end.setUTCHours(0, 0, 0, 0);
|
||||
const start = new Date(end.getTime() - YEARS * 365 * DAY);
|
||||
const CHUNK = 30 * DAY;
|
||||
for (let from = start.getTime(); from < end.getTime(); from += CHUNK) {
|
||||
const chunkFrom = new Date(from);
|
||||
const chunkTo = new Date(Math.min(from + CHUNK, end.getTime()));
|
||||
await prisma.$transaction([
|
||||
prisma.$executeRaw`SET LOCAL statement_timeout = 0`,
|
||||
prisma.$executeRaw`
|
||||
INSERT INTO measurements (id, user_id, type, unit, source, value, measured_at, created_at, updated_at)
|
||||
SELECT 'big-' || (extract(epoch FROM ts)::bigint / 60)::text, ${BIG}, 'PULSE', 'bpm', 'APPLE_HEALTH',
|
||||
60 + ((extract(epoch FROM ts)::bigint / 60) % 40),
|
||||
ts, now(), now()
|
||||
FROM generate_series(
|
||||
${chunkFrom}::timestamptz,
|
||||
${chunkTo}::timestamptz - interval '1 minute',
|
||||
interval '1 minute'
|
||||
) AS s(ts)
|
||||
WHERE extract(hour FROM ts)::int % 7 <> 3 OR extract(minute FROM ts)::int = 0
|
||||
`,
|
||||
]);
|
||||
}
|
||||
await prisma.$transaction([
|
||||
prisma.$executeRaw`SET LOCAL statement_timeout = 0`,
|
||||
prisma.$executeRaw`ANALYZE measurements`,
|
||||
]);
|
||||
}, 600_000);
|
||||
|
||||
async function peakHeapMb(work: () => Promise<unknown>) {
|
||||
|
||||
Reference in new issue
Block a user