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.
This commit is contained in:
Evandro Fonseca Junior committed 2026-09-14 08:31:01 -03:00
1 parent 7a54e2dbeb
commit 0852274102
1 file changed
+6 -1
+6 -1
View File
@@ -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]);