Skip to content

Commit

Permalink
cleanup and test
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 9, 2024
1 parent 28eff92 commit 28573b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/manager.ts
Expand Up @@ -473,17 +473,18 @@ export class Manager<
/**
* Called upon a socket close.
*
* @param socket
* @param nsp - the namespace of the socket being closed
* @private
*/
_destroy(closingSocket: Socket): void {
delete this.nsps[closingSocket.nsp];
_destroy(nsp: string): void {
delete this.nsps[nsp];

const nsps = Object.keys(this.nsps);

for (const nsp of nsps) {
const socket = this.nsps[nsp];
const remainingSocket = this.nsps[nsp];

if (socket.active) {
if (remainingSocket.active) {
debug("socket %s is still active, skipping close", nsp);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/socket.ts
Expand Up @@ -881,7 +881,7 @@ export class Socket<
this.subs.forEach((subDestroy) => subDestroy());
this.subs = undefined;
}
this.io["_destroy"](this);
this.io._destroy(this.nsp);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/connection.ts
Expand Up @@ -60,6 +60,19 @@ describe("connection", () => {
s2.disconnect();
});

it("should start a single connection with different namespaces (after disconnection)", () => {
const s1 = io("/foo");
const s2 = io("/bar");

s2.disconnect();

const s3 = io("/bar");

expect(s3.io).to.be(s1.io);
s1.disconnect();
s3.disconnect();
});

it("should work with acks", () => {
return wrap((done) => {
const socket = io(BASE_URL, { forceNew: true });
Expand Down

0 comments on commit 28573b6

Please sign in to comment.