From 717eb1d1e12265f5cc3b5737bb1cdf4ee9d5f7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 31 Oct 2026 10:22:27 +0100 Subject: [PATCH] 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. --- tests/integration/measurement-rollups.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/integration/measurement-rollups.test.ts b/tests/integration/measurement-rollups.test.ts index c813fdebf..795b30c2a 100644 --- a/tests/integration/measurement-rollups.test.ts +++ b/tests/integration/measurement-rollups.test.ts @@ -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.