test(rollups): wait for the warm-up refresh before writing the next row

The summaries read starts ensureUserRollupsFresh detached. When the third
row's DAY bucket landed before that refresh, WEIGHT counted as covered by
its one bucket and the read reported a count of 1; a CI shard hit exactly
that.
This commit is contained in:
Marc-André Bombeck committed 2026-10-31 10:22:27 +01:00
1 parent 087c8868cf
commit 717eb1d1e1
1 file changed
+6 -1
@@ -25,6 +25,7 @@
*/
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { settleBackgroundTasks } from "@/lib/logging/background-tasks";
import { getPrismaClient, truncateAllTables } from "./setup";
import {
ROLLUP_FULL_BACKFILL_QUEUE,
@@ -580,10 +581,14 @@ describe("measurement rollups — integration", () => {
],
});
// Warm-up read populates the rollups via `ensureUserRollupsFresh`.
// Warm-up read populates the rollups via `ensureUserRollupsFresh`. The
// read starts it detached, so wait for it: otherwise the third row's
// bucket can land first and the next read takes the one WEIGHT bucket
// for the whole history.
const before = await buildComprehensiveAggregate(user.id);
expect(before.summaries.WEIGHT.count).toBe(2);
expect(before.summaries.WEIGHT.mean).toBe(80.5);
await settleBackgroundTasks();
// Insert a third row and synchronously refresh the DAY bucket the
// way the write-path hooks do.