From f9068a21ca6591c4d66afab37a29ed9db9b4438e Mon Sep 17 00:00:00 2001 From: Abdalla <61162028+abdoahmed07@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:54:46 +0100 Subject: [PATCH] Update socket-timeout.ts test(sio): add tests for acks upon client disconnection --- packages/socket.io/test/socket-timeout.ts | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/socket.io/test/socket-timeout.ts b/packages/socket.io/test/socket-timeout.ts index 62f36807b8..8d520eb168 100644 --- a/packages/socket.io/test/socket-timeout.ts +++ b/packages/socket.io/test/socket-timeout.ts @@ -84,4 +84,40 @@ describe("timeout", () => { success(done, io, client); }); }); + it("should timeout if the client disconnects before acknowledging the event", (done) => { + const io = new Server(0); + const client = createClient(io, "/"); + + client.on("echo", () => { + client.disconnect(); + }); + + io.on("connection", (socket) => { + socket.timeout(50).emit("echo", (err) => { + expect(err).to.be.an(Error); + expect(socket.connected).to.be(false); + success(done, io, client); + }); + }); + }); + + it("should timeout if the client disconnects before acknowledging the event (promise)", (done) => { + const io = new Server(0); + const client = createClient(io, "/"); + + client.on("echo", () => { + client.disconnect(); + }); + + io.on("connection", async (socket) => { + try { + await socket.timeout(50).emitWithAck("echo"); + expect().fail(); + } catch (err) { + expect(err).to.be.an(Error); + expect(socket.connected).to.be(false); + success(done, io, client); + } + }); + }); });