From 54b91df0a2d57c8b001a1386dab7a065fc831d87 Mon Sep 17 00:00:00 2001 From: zan mlakar Date: Wed, 7 Oct 2026 21:36:31 +0200 Subject: [PATCH] test(sio-client): cover retry queue reconnection and exhaustion --- packages/socket.io-client/test/retry.ts | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/socket.io-client/test/retry.ts b/packages/socket.io-client/test/retry.ts index 9ceca208b1..80ecc72fa9 100644 --- a/packages/socket.io-client/test/retry.ts +++ b/packages/socket.io-client/test/retry.ts @@ -111,6 +111,63 @@ describe("retry", () => { }); }); + it("should retry an unacknowledged packet upon reconnection without ackTimeout", () => { + return wrap((done) => { + const socket = io(BASE_URL, { + forceNew: true, + retries: 1, + reconnectionDelay: 10, + reconnectionDelayMax: 10, + }); + + let count = 0; + socket.on("ack", () => { + count++; + if (count === 1) { + socket.io.engine.close(); + } else { + expect(count).to.eql(2); + success(done, socket); + } + }); + + // The server emits "ack" when it receives this event, but does not + // acknowledge it. The pending packet must be sent on the new connection. + socket.emit("ack"); + socket.emit("echo", "next", () => { + done(new Error("should not skip the unacknowledged packet")); + }); + }); + }); + + it("should drain the next packet after exhausting the retries", () => { + return wrap((done) => { + const socket = io(BASE_URL, { + forceNew: true, + retries: 1, + ackTimeout: 50, + }); + + let attempts = 0; + let failed = false; + socket.on("ack", () => { + attempts++; + }); + + socket.emit("ack", (err) => { + expect(err).to.be.an(Error); + expect(attempts).to.eql(2); + failed = true; + }); + socket.emit("echo", "next", (err, value) => { + expect(failed).to.be(true); + expect(err).to.be(null); + expect(value).to.eql("next"); + success(done, socket); + }); + }); + }); + it("should not emit a packet twice in the 'connect' handler", () => { return wrap((done) => { const socket = io(BASE_URL, {