|
| 1 | +import { TestIrcServer } from "matrix-org-irc"; |
| 2 | +import { IrcBridgeE2ETest } from "../util/e2e-test"; |
| 3 | +import { describe, it } from "@jest/globals"; |
| 4 | + |
| 5 | +const describeif = IrcBridgeE2ETest.usingRedis ? describe : describe.skip; |
| 6 | + |
| 7 | +describeif('Connection pooling', () => { |
| 8 | + let testEnv: IrcBridgeE2ETest; |
| 9 | + |
| 10 | + beforeEach(async () => { |
| 11 | + // Initial run of the bridge to setup a testing environment |
| 12 | + testEnv = await IrcBridgeE2ETest.createTestEnv({ |
| 13 | + matrixLocalparts: ['alice'], |
| 14 | + ircNicks: ['bob'], |
| 15 | + config: { |
| 16 | + connectionPool: { |
| 17 | + redisUrl: 'unused', |
| 18 | + persistConnectionsOnShutdown: true, |
| 19 | + } |
| 20 | + } |
| 21 | + }); |
| 22 | + await testEnv.setUp(); |
| 23 | + }) |
| 24 | + |
| 25 | + // Ensure we always tear down |
| 26 | + afterEach(() => { |
| 27 | + return testEnv.tearDown(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should be able to shut down the bridge and start back up again', async () => { |
| 31 | + const channel = `#${TestIrcServer.generateUniqueNick("test")}`; |
| 32 | + |
| 33 | + const { homeserver } = testEnv; |
| 34 | + const alice = homeserver.users[0].client; |
| 35 | + const { bob } = testEnv.ircTest.clients; |
| 36 | + |
| 37 | + // Create the channel |
| 38 | + await bob.join(channel); |
| 39 | + |
| 40 | + const adminRoomId = await testEnv.createAdminRoomHelper(alice); |
| 41 | + const cRoomId = await testEnv.joinChannelHelper(alice, adminRoomId, channel); |
| 42 | + |
| 43 | + // And finally wait for bob to appear. |
| 44 | + const bobUserId = `@irc_${bob.nick}:${homeserver.domain}`; |
| 45 | + await alice.waitForRoomEvent( |
| 46 | + {eventType: 'm.room.member', sender: bobUserId, stateKey: bobUserId, roomId: cRoomId} |
| 47 | + ); |
| 48 | + |
| 49 | + |
| 50 | + // Send some messages |
| 51 | + let aliceMsg = bob.waitForEvent('message', 10000); |
| 52 | + let bobMsg = alice.waitForRoomEvent( |
| 53 | + {eventType: 'm.room.message', sender: bobUserId, roomId: cRoomId} |
| 54 | + ); |
| 55 | + alice.sendText(cRoomId, "Hello bob!"); |
| 56 | + await aliceMsg; |
| 57 | + bob.say(channel, "Hi alice!"); |
| 58 | + await bobMsg; |
| 59 | + |
| 60 | + console.log('Recreating bridge'); |
| 61 | + |
| 62 | + // Now kill the bridge, do NOT kill the dependencies. |
| 63 | + await testEnv.recreateBridge(); |
| 64 | + await testEnv.setUp(); |
| 65 | + |
| 66 | + aliceMsg = bob.waitForEvent('message', 10000); |
| 67 | + bobMsg = alice.waitForRoomEvent( |
| 68 | + {eventType: 'm.room.message', sender: bobUserId, roomId: cRoomId} |
| 69 | + ); |
| 70 | + alice.sendText(cRoomId, "Hello bob!"); |
| 71 | + await aliceMsg; |
| 72 | + bob.say(channel, "Hi alice!"); |
| 73 | + await bobMsg; |
| 74 | + }); |
| 75 | + |
| 76 | + it('should be able to recover from legacy client state', async () => { |
| 77 | + const channel = `#${TestIrcServer.generateUniqueNick("test")}`; |
| 78 | + |
| 79 | + const { homeserver } = testEnv; |
| 80 | + const alice = homeserver.users[0].client; |
| 81 | + const { bob } = testEnv.ircTest.clients; |
| 82 | + |
| 83 | + // Create the channel |
| 84 | + await bob.join(channel); |
| 85 | + |
| 86 | + const adminRoomId = await testEnv.createAdminRoomHelper(alice); |
| 87 | + const cRoomId = await testEnv.joinChannelHelper(alice, adminRoomId, channel); |
| 88 | + |
| 89 | + // And finally wait for bob to appear. |
| 90 | + const bobUserId = `@irc_${bob.nick}:${homeserver.domain}`; |
| 91 | + await alice.waitForRoomEvent( |
| 92 | + {eventType: 'm.room.member', sender: bobUserId, stateKey: bobUserId, roomId: cRoomId} |
| 93 | + ); |
| 94 | + |
| 95 | + |
| 96 | + // Send some messages |
| 97 | + let aliceMsg = bob.waitForEvent('message', 10000); |
| 98 | + let bobMsg = alice.waitForRoomEvent( |
| 99 | + {eventType: 'm.room.message', sender: bobUserId, roomId: cRoomId} |
| 100 | + ); |
| 101 | + alice.sendText(cRoomId, "Hello bob!"); |
| 102 | + await aliceMsg; |
| 103 | + bob.say(channel, "Hi alice!"); |
| 104 | + await bobMsg; |
| 105 | + |
| 106 | + // Now kill the bridge, do NOT kill the dependencies. |
| 107 | + await testEnv.recreateBridge(); |
| 108 | + await testEnv.setUp(); |
| 109 | + |
| 110 | + aliceMsg = bob.waitForEvent('message', 10000); |
| 111 | + bobMsg = alice.waitForRoomEvent( |
| 112 | + {eventType: 'm.room.message', sender: bobUserId, roomId: cRoomId} |
| 113 | + ); |
| 114 | + alice.sendText(cRoomId, "Hello bob!"); |
| 115 | + await aliceMsg; |
| 116 | + bob.say(channel, "Hi alice!"); |
| 117 | + await bobMsg; |
| 118 | + }); |
| 119 | +}); |
0 commit comments