Skip to content

Commit 26b91a7

Browse files
committed
Cover held ordering locks in cfworkers
src/mod.test.ts covered the ordering lock being taken and released, but never the case where processMessage() finds one already held and returns shouldProcess: false. test/mq.test.ts covers that branch by stubbing get() to return a lock unconditionally; this test takes the lock with a real processMessage() call and sends a second message for the same key without releasing it, so it also proves the key that processMessage() writes is the one it later reads back. Closes #879 Changelog: none Assisted-by: Claude Code:claude-opus-5
1 parent 81416ae commit 26b91a7

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/cfworkers/src/mod.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,26 @@ describe("WorkersMessageQueue", () => {
373373
__fedify_payload__: { id: "test-message" },
374374
});
375375
});
376+
377+
it("processMessage() - returns shouldProcess=false when lock exists", async () => {
378+
const orderingKv = new MockKvNamespace();
379+
const queue = new WorkersMessageQueue(mockQueue, { orderingKv });
380+
381+
const first = await queue.processMessage({
382+
__fedify_ordering_key__: "key1",
383+
__fedify_payload__: { id: "first" },
384+
});
385+
386+
expect(first.shouldProcess).toBe(true);
387+
expect(first.message).toEqual({ id: "first" });
388+
389+
const second = await queue.processMessage({
390+
__fedify_ordering_key__: "key1",
391+
__fedify_payload__: { id: "second" },
392+
});
393+
394+
expect(second.shouldProcess).toBe(false);
395+
expect(second.message).toBeUndefined();
396+
expect(second.release).toBeUndefined();
397+
});
376398
});

0 commit comments

Comments
 (0)