release: WRNexusJS 0.8.0
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-02 23:18:51 +05:30
parent 87507edf59
commit 586a6db8ff
625 changed files with 243608 additions and 11210 deletions
+73
View File
@@ -135,6 +135,44 @@ test("deduplicates, lists and cancels queued work", async () => {
expect(queue.cancel(first.id)).toBe(false);
});
test("enforces capacity and can retry dead-lettered work", async () => {
const queue = createQueue({ capacity: 1, maxAttempts: 1 });
const job = await queue.add("work", {});
await expect(queue.add("work", {})).rejects.toThrow("WRN-QUEUE-CAPACITY");
queue.process("work", () => {
throw new Error("nope");
});
await queue.drain();
expect(queue.failed().map(({ id }) => id)).toEqual([job.id]);
expect(await queue.retry(job.id)).toBe(true);
expect(queue.failed()).toHaveLength(0);
expect(queue.size()).toBe(1);
});
test("cancels active work with an AbortSignal and force-shuts down", async () => {
const queue = createQueue();
let aborted = false;
queue.process(
"work",
(_job, { signal }) =>
new Promise<void>((resolve) => {
signal.addEventListener("abort", () => {
aborted = true;
resolve();
});
}),
);
const job = await queue.add("work", {});
const draining = queue.drain();
await Promise.resolve();
expect(queue.cancel(job.id)).toBe(true);
await draining;
expect(aborted).toBe(true);
expect(queue.size()).toBe(0);
await queue.shutdown({ force: true });
await expect(queue.add("work", {})).rejects.toThrow("WRN-QUEUE-CLOSED");
});
test("runs typed workflows and parses supported cron expressions", async () => {
const workflow = defineWorkflow<number>("double-and-label", [
{ name: "double", run: (value: number) => value * 2 },
@@ -190,3 +228,38 @@ test("durable queue does not remove a job before its handler succeeds", async ()
expect(visibleDuringHandler).toBe(true);
expect(await store.get(job.id)).toBeNull();
});
test("durable queue supports capacity, cancellation, and shutdown", async () => {
const store = memoryQueueStore();
const queue = createDurableQueue({ store, capacity: 1 });
const job = await queue.add("work", {});
await expect(queue.add("work", {})).rejects.toThrow("WRN-QUEUE-CAPACITY");
expect((await queue.list()).map(({ id }) => id)).toEqual([job.id]);
expect(await queue.cancel(job.id)).toBe(true);
expect(await queue.cancel(job.id)).toBe(false);
await queue.shutdown();
await expect(queue.add("work", {})).rejects.toThrow("WRN-QUEUE-CLOSED");
});
test("force shutdown aborts an active durable job", async () => {
const store = memoryQueueStore();
const queue = createDurableQueue({ store });
let aborted = false;
queue.process(
"work",
(_job, { signal }) =>
new Promise<void>((resolve) => {
signal.addEventListener("abort", () => {
aborted = true;
resolve();
});
}),
);
const job = await queue.add("work", {});
const draining = queue.drain();
await Promise.resolve();
await queue.shutdown({ force: true });
await draining;
expect(aborted).toBe(true);
expect(await store.get(job.id)).toBeNull();
});