Skip to content

Commit 1beeb54

Browse files
committed
test(run-engine): pin dequeue-emitted gauges so a sampling regression fails the suite
The gauge assertions were all satisfiable by enqueue-emitted gauges, so breaking the dequeue scripts' sample-at-return wrapper left the suite green. The base test now requires the post-admission reading (running 1, queued 0) and the CK test requires the wildcard aggregate only the CK dequeue emits. Verified by mutation: disabling the wrapper fails both.
1 parent e2153e2 commit 1beeb54

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

internal-packages/run-engine/src/run-queue/metrics.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ describe("RunQueue queue-metrics emission", () => {
123123

124124
const entries = await waitForEntries(redis, definition, (es) => {
125125
const seen = es.map((e) => e.fields.op);
126-
return ["enqueue", "gauge", "started", "ack"].every((o) => seen.includes(o));
126+
if (!["enqueue", "gauge", "started", "ack"].every((o) => seen.includes(o))) return false;
127+
return es.some(
128+
(e) => e.fields.op === "gauge" && e.fields.cc === "1" && e.fields.ql === "0"
129+
);
127130
});
128131
const ops = entries.map((e) => e.fields.op);
129132
expect(ops).toContain("enqueue");
@@ -141,6 +144,14 @@ describe("RunQueue queue-metrics emission", () => {
141144
expect(gauge!.fields.ckq).toBeUndefined();
142145
expect(gauge!.fields.ckw).toBeUndefined();
143146

147+
// Pins the dequeue script's sample-at-return wrapper: only the dequeue emits the
148+
// post-admission reading (running 1, queued 0); the enqueue gauge sees the inverse.
149+
const dequeueGauge = entries.find(
150+
(e) => e.fields.op === "gauge" && e.fields.cc === "1" && e.fields.ql === "0"
151+
);
152+
assertGauge(dequeueGauge);
153+
expect(dequeueGauge!.fields.q).toContain("task/my-task");
154+
144155
// The first counter emission also seeds a cum=0 baseline (no wait); the real reading
145156
// carries wait. Pick the reading (cum > 0).
146157
const started = entries.find((e) => e.fields.op === "started" && Number(e.fields.cum) > 0);
@@ -283,14 +294,13 @@ describe("RunQueue queue-metrics emission", () => {
283294
expect(dequeued?.messageId).toBe(message.runId);
284295

285296
const entries = await waitForEntries(redis, definition, (es) =>
286-
es.some(
287-
(e) => e.fields.op === "gauge" && e.fields.q.includes(":ck:") && e.fields.thr === "0"
288-
)
297+
es.some((e) => e.fields.op === "gauge" && e.fields.q.includes(":ck:*"))
289298
);
290299
const gauges = entries.filter((e) => e.fields.op === "gauge");
291300
expect(gauges.length).toBeGreaterThan(0);
292-
// The aggregate CK dequeue gauge targets the CK wildcard and never sets thr.
293-
const aggregate = gauges.find((e) => e.fields.q.includes(":ck:") && e.fields.thr === "0");
301+
// The aggregate gauge targets the CK wildcard and only the CK dequeue script emits
302+
// it, so this pins that script's sample-at-return wrapper.
303+
const aggregate = gauges.find((e) => e.fields.q.includes(":ck:*"));
294304
assertGauge(aggregate);
295305
expect(Number(aggregate!.fields.ql)).toBeGreaterThanOrEqual(0);
296306
expect(Number(aggregate!.fields.cc)).toBeGreaterThanOrEqual(0);

0 commit comments

Comments
 (0)