Skip to content

Commit 70a4b95

Browse files
committed
test(clickhouse): keep queue metrics fixtures within TTL
1 parent d90f06b commit 70a4b95

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

internal-packages/clickhouse/src/queueMetrics.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ import type { QueueMetricsRawV1Input } from "./queueMetrics.js";
66
const ORG = "org_qm";
77
const PROJECT = "project_qm";
88
const ENV = "env_qm";
9-
const EVENT_TIME = "2026-06-30 12:00:05"; // all rows land in the 10s bucket starting 12:00:00
9+
10+
function clickhouseDateTime(timestamp: number) {
11+
return new Date(timestamp).toISOString().slice(0, 19).replace("T", " ");
12+
}
13+
14+
// Keep fixtures within the tables' TTLs while preserving deterministic bucket
15+
// relationships. Subtract a minute before rounding so no fixture lands in the future.
16+
const TEST_MINUTE = Math.floor((Date.now() - 60_000) / 60_000) * 60_000;
17+
const EVENT_TIME = clickhouseDateTime(TEST_MINUTE + 5_000);
18+
const NEXT_BUCKET_EVENT_TIME = clickhouseDateTime(TEST_MINUTE + 15_000);
19+
const RANKING_START_TIME = clickhouseDateTime(TEST_MINUTE - 10 * 60_000);
1020

1121
function base(op: QueueMetricsRawV1Input["op"], queue: string): QueueMetricsRawV1Input {
1222
return {
@@ -246,7 +256,7 @@ describe("queue_metrics_v1", () => {
246256
{ ...base("gauge", "roll-b"), running: 2, queued: 1, env_running: 45, env_limit: 50 },
247257
{
248258
...base("gauge", "roll-a"),
249-
event_time: "2026-06-30 12:00:15",
259+
event_time: NEXT_BUCKET_EVENT_TIME,
250260
running: 1,
251261
queued: 2,
252262
env_running: 20,
@@ -352,7 +362,7 @@ describe("queue_metrics_v1", () => {
352362
organizationId: ORG,
353363
projectId: PROJECT,
354364
environmentId: ENV,
355-
startTime: "2026-06-30 11:50:00",
365+
startTime: RANKING_START_TIME,
356366
nameContains: "rank-",
357367
byQueuedOnly: 0,
358368
};

0 commit comments

Comments
 (0)