From 0852274102934a9f3d10cd1415817340aa599ec8 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Mon, 14 Sep 2026 08:31:01 -0300 Subject: [PATCH] test: stop assuming a fixed envelope delivery time in the bus ledger test "Bus local server memoizes completed and in-flight request results" sent two envelopes, slept a fixed 5 ms and then asserted that the handler had already run once. On a slower CI runner the first envelope can still be in the socket queue at that point, so the run failed with 0 !== 1 (run 34838232340). Wait (bounded, 5 s deadline) until the first envelope reaches the handler before asserting. The duplicate stays in flight because the gate is only released after the assertion, so the memoization guarantee under test is unchanged. --- tests/bus.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/bus.test.ts b/tests/bus.test.ts index f854ced..8d6ae6a 100644 --- a/tests/bus.test.ts +++ b/tests/bus.test.ts @@ -1060,7 +1060,12 @@ test("Bus local server memoizes completed and in-flight request results", async }; const first = sendTelegramBusLocalEnvelope({ socketPath, envelope }); const duplicate = sendTelegramBusLocalEnvelope({ socketPath, envelope }); - await new Promise((resolve) => setTimeout(resolve, 5)); + // Wait for the first envelope to reach the handler instead of assuming a + // fixed delivery time; the duplicate must still be memoized while in flight. + const deliveryDeadlineMs = Date.now() + 5_000; + while (executions === 0 && Date.now() < deliveryDeadlineMs) { + await new Promise((resolve) => setTimeout(resolve, 5)); + } assert.equal(executions, 1); release?.(); const [firstResult, duplicateResult] = await Promise.all([first, duplicate]);