Skip to content

Commit

Permalink
Add a test to ensure that the irc client state doesn't bloat on VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jul 25, 2023
1 parent 7cfb057 commit 9ba19a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/1753.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure we don't bloat irc supported state.
27 changes: 27 additions & 0 deletions spec/e2e/pooling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,31 @@ describeif('Connection pooling', () => {
bob.say(channel, "Hi alice!");
await bobMsg;
});

it.only('should store the IRC client state once', async () => {
const channel = `#${TestIrcServer.generateUniqueNick("test")}`;
const { homeserver, ircBridge } = testEnv;
const { client, userId } = homeserver.users[0];
const adminRoomId = await testEnv.createAdminRoomHelper(client);

// Ensure we join IRC.
const cRoomId = await testEnv.joinChannelHelper(client, adminRoomId, channel);
await client.sendText(cRoomId, "Hello bob!");


const bridgedClient = await ircBridge.getBridgedClient(ircBridge.getServers()[0], userId);
await bridgedClient.waitForConnected();
const ircClient = await bridgedClient.assertConnected();

// This is the original state of supported. We clone the object to be safe.
const expectedState = JSON.parse(JSON.stringify(ircClient.supported));

// Request VERSION to re-request state.
await bridgedClient.sendCommands('VERSION');
await new Promise<void>(resolve => setTimeout(resolve, 2000));
const newState = { ...ircClient.supported };

expect(expectedState).toEqual(newState);
});

});
2 changes: 1 addition & 1 deletion src/irc/BridgedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ export class BridgedClient extends EventEmitter {
return this.connectDefer.promise;
}

private assertConnected(): Client {
public assertConnected(): Client {
if (this.state.status !== BridgedClientStatus.CONNECTED) {
throw Error('Client is not connected');
}
Expand Down

0 comments on commit 9ba19a1

Please sign in to comment.