From 26b91a76edb32e2ce4c4b3103927f2225e0cbac1 Mon Sep 17 00:00:00 2001 From: seongmin36 Date: Mon, 31 Aug 2026 01:30:30 +0900 Subject: [PATCH] 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 https://github.com/fedify-dev/fedify/issues/879 Changelog: none Assisted-by: Claude Code:claude-opus-5 --- packages/cfworkers/src/mod.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/cfworkers/src/mod.test.ts b/packages/cfworkers/src/mod.test.ts index 39ac7e485..54cf47100 100644 --- a/packages/cfworkers/src/mod.test.ts +++ b/packages/cfworkers/src/mod.test.ts @@ -373,4 +373,26 @@ describe("WorkersMessageQueue", () => { __fedify_payload__: { id: "test-message" }, }); }); + + it("processMessage() - returns shouldProcess=false when lock exists", async () => { + const orderingKv = new MockKvNamespace(); + const queue = new WorkersMessageQueue(mockQueue, { orderingKv }); + + const first = await queue.processMessage({ + __fedify_ordering_key__: "key1", + __fedify_payload__: { id: "first" }, + }); + + expect(first.shouldProcess).toBe(true); + expect(first.message).toEqual({ id: "first" }); + + const second = await queue.processMessage({ + __fedify_ordering_key__: "key1", + __fedify_payload__: { id: "second" }, + }); + + expect(second.shouldProcess).toBe(false); + expect(second.message).toBeUndefined(); + expect(second.release).toBeUndefined(); + }); });