Skip to content

Commit

Permalink
More sync testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Aug 1, 2023
1 parent 2ff8cd0 commit b23eb87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
68 changes: 52 additions & 16 deletions spec/e2e/scaling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestIrcServer } from "matrix-org-irc";
import { ChanData, TestIrcServer } from "matrix-org-irc";
import { IrcBridgeE2ETest } from "../util/e2e-test";
import { describe, it, expect } from "@jest/globals";
import { delay } from "../../src/promiseutil";
Expand Down Expand Up @@ -43,34 +43,70 @@ describe('Bridge scaling test', () => {
{eventType: 'm.room.member', sender: bobUserId, stateKey: bobUserId, roomId: cRoomId}
);

// Send some messages
const aliceMsg = bob.waitForEvent('message', 10000);
const bobMsg = alice.waitForRoomEvent(
{eventType: 'm.room.message', sender: bobUserId, roomId: cRoomId}
);
alice.sendText(cRoomId, "Hello bob!");
await aliceMsg;
bob.say(channel, "Hi alice!");
await bobMsg;
// Have all the Matrix users join
const usersToJoin = homeserver.users.filter(u => testEnv.opts.matrixSynclessLocalparts?.includes(u.localpart))
for (const mxUser of usersToJoin) {
await mxUser.client.joinRoom(cRoomId);
}

// We now need to wait for all the expected joins on the IRC side.
const chanData = bob.chanData(channel, false);
if (!chanData) {
throw Error('Expected to have channel data for channel');
}

// Track all the joins that we see.
const ircJoins: {channel: string, nick: string}[] = [];
bob.on('join', (joinChannel, nick) => ircJoins.push({channel: joinChannel, nick}));
do {
await delay(500);
} while (chanData?.users.size < homeserver.users.length)

// Now check that all the users joined.
for (const mxUser of usersToJoin) {
expect(chanData.users.keys()).toContain(`M-${mxUser.localpart}`)
}
}, 100_000);

it('should be able to sync many users on startup', async () => {
const channel = `#${TestIrcServer.generateUniqueNick("test")}`;
const { homeserver } = testEnv;
const alice = homeserver.users[0].client;
const { bob } = testEnv.ircTest.clients;

// Create the channel
await bob.join(channel);

const adminRoomId = await testEnv.createAdminRoomHelper(alice);
const cRoomId = await testEnv.joinChannelHelper(alice, adminRoomId, channel);

// And finally wait for bob to appear.
const bobUserId = `@irc_${bob.nick}:${homeserver.domain}`;
await alice.waitForRoomEvent(
{eventType: 'm.room.member', sender: bobUserId, stateKey: bobUserId, roomId: cRoomId}
);

// Have all the Matrix users join
const usersToJoin = homeserver.users.filter(u => testEnv.opts.matrixSynclessLocalparts?.includes(u.localpart))
for (const mxUser of usersToJoin) {
await mxUser.client.joinRoom(cRoomId);
}

// Now kill the bridge
await testEnv.recreateBridge();
await testEnv.setUp();


// We now need to wait for all the expected joins on the IRC side.
while (ircJoins.length < usersToJoin.length) {
await delay(2000);
const chanData = bob.chanData(channel, false);
if (!chanData) {
throw Error('Expected to have channel data for channel');
}

do {
await delay(500);
} while (chanData?.users.size < homeserver.users.length)

// Now check that all the users joined.
for (const mxUser of usersToJoin) {
expect(ircJoins).toContainEqual({ channel, nick: `M-${mxUser.localpart}`});
expect(chanData.users.keys()).toContain(`M-${mxUser.localpart}`)
}
}, 100_000);
});
5 changes: 5 additions & 0 deletions spec/util/e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ export class IrcBridgeE2ETest {
displayName: "$NICK",
joinAttempts: 3,
},
ircClients: {
...IrcServer.DEFAULT_CONFIG.ircClients,
// Set a sensibly high max.
maxClients: 100_000,
},
dynamicChannels: {
enabled: true,
createAlias: true,
Expand Down

0 comments on commit b23eb87

Please sign in to comment.