Skip to content

Commit

Permalink
test: broadcast with a single ack
Browse files Browse the repository at this point in the history
Calling fetchSockets() and then broadcasting to a remote socket with an
acknowledgement would fail in version < 4.7.3.

```js
const sockets = await io.fetchSockets();
const result = await sockets[0].emitWithAck("ping");

// result was always null regardless of the response of the client
```

Related: socketio/socket.io@df8e70f
  • Loading branch information
darrachequesne committed Jan 23, 2024
1 parent 18f47eb commit 6d43c14
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ describe("@socket.io/postgres-adapter", () => {
done();
});
});

it("broadcasts with a single acknowledgement (local)", async () => {
clientSockets[0].on("test", () => expect().fail());
clientSockets[1].on("test", (cb) => cb(2));
clientSockets[2].on("test", () => expect().fail());

const response = await serverSockets[1].emitWithAck("test");
expect(response).to.eql(2);
});

it("broadcasts with a single acknowledgement (remote)", async () => {
clientSockets[0].on("test", () => expect().fail());
clientSockets[1].on("test", (cb) => cb(2));
clientSockets[2].on("test", () => expect().fail());

const sockets = await servers[0].in(serverSockets[1].id).fetchSockets();
expect(sockets.length).to.eql(1);

const response = await sockets[0].timeout(500).emitWithAck("test");
expect(response).to.eql(2);
});
});

describe("socketsJoin", () => {
Expand Down

0 comments on commit 6d43c14

Please sign in to comment.