Skip to content

Commit 5f832f5

Browse files
committed
test(run-engine): cover error isolation and the retry it triggers in the pause sweep
A run that throws on its way back was the one failure mode with no coverage: a rejected script call never increments the skipped count, so without both the per-message isolation and the retry-on-error condition a transient failure would end the sweep with those runs still admitted and still on the worker queue. Seeds an unreturnable run alongside a healthy one and asserts the healthy one still comes back, the failure is counted, and the pass is retried.
1 parent ce51b31 commit 5f832f5

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

internal-packages/run-engine/src/run-queue/tests/returnUnclaimedMessagesToQueue.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,59 @@ describe("RunQueue.returnUnclaimedMessagesToQueue", () => {
711711
}
712712
);
713713

714+
redisTest(
715+
"isolates a run that fails to return and retries the pass",
716+
async ({ redisContainer }) => {
717+
const queue = createRunQueue(redisContainer);
718+
const redis = createRedisClient(redisContainer);
719+
720+
try {
721+
await queue.enqueueMessage({
722+
env: authenticatedEnvDev,
723+
message: messageFor({ runId: "r1" }),
724+
workerQueue: authenticatedEnvDev.id,
725+
skipDequeueProcessing: true,
726+
});
727+
728+
await queue.processMasterQueueForEnvironment(authenticatedEnvDev.id, 10);
729+
730+
const envConcurrencyKey = `runqueue:test:${testOptions.keys.envCurrentConcurrencyKey(
731+
authenticatedEnvDev
732+
)}`;
733+
const badMessageKey = `runqueue:test:${testOptions.keys.messageKey(
734+
authenticatedEnvDev.organization.id,
735+
"r-bad"
736+
)}`;
737+
738+
await redis.sadd(envConcurrencyKey, "r-bad");
739+
await redis.set(
740+
badMessageKey,
741+
JSON.stringify({
742+
...messageFor({ runId: "r-bad" }),
743+
version: "2",
744+
workerQueue: authenticatedEnvDev.id,
745+
queue: "not-a-queue-key",
746+
})
747+
);
748+
749+
const result = await queue.returnUnclaimedMessagesToQueue({
750+
env: authenticatedEnvDev,
751+
passDelayMs: 10,
752+
});
753+
754+
expect(result.errors).toBeGreaterThanOrEqual(1);
755+
expect(result.passes).toBe(2);
756+
757+
expect(result.returned).toBe(1);
758+
expect(await queue.lengthOfQueue(authenticatedEnvDev, "task/my-task")).toBe(1);
759+
expect(await queue.peekAllOnWorkerQueue(authenticatedEnvDev.id)).toHaveLength(0);
760+
} finally {
761+
await redis.quit();
762+
await queue.quit();
763+
}
764+
}
765+
);
766+
714767
redisTest("is idempotent when run twice", async ({ redisContainer }) => {
715768
const queue = createRunQueue(redisContainer);
716769

0 commit comments

Comments
 (0)