Skip to content

Commit b850e45

Browse files
authored
Remove debug leftovers from a test. (#314)
* Remove debug leftovers from a test. This is really terrible and has meant whenever anyone has run `yarn test:integration` they have only been running this test. πŸ’€πŸ’€πŸ’€ https://www.youtube.com/watch?v=jmX-tzSOFE0 * Set a default timeout for integration tests that is 5 minutes long. Seriously, I don't think there is much to gain by making people guess a reasnoble time for a test to complete in all the time, especially with how much Synapse changes in response time and all of the machines involved in running these tests. * Warn when giving up on being throttled * For some reason it takes longer for events to appear in /state no i am not going to track down why yet. * Rate limiting got a lot more aggresive. matrix-org/synapse#13018 Rate limiting in Synapse used to reset the burst count and remove the backoff when you were spamming continuously, now it doesn't. Ideally we'd rewrite the rate limiting logic to back off for longer than suggested so we could get burst again, but for now lets just unblock CI by reducing the number of events we send in these tests.
1 parent ac2e736 commit b850e45

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint": "tslint --project ./tsconfig.json -t stylish",
1414
"start:dev": "yarn build && node --async-stack-traces lib/index.js",
1515
"test": "ts-mocha --project ./tsconfig.json test/commands/**/*.ts",
16-
"test:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --require test/integration/fixtures.ts --project ./tsconfig.json \"test/integration/**/*Test.ts\"",
16+
"test:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\"",
1717
"test:manual": "NODE_ENV=harness ts-node test/integration/manualLaunchScript.ts",
1818
"version": "sed -i '/# version automated/s/[0-9][0-9]*\\.[0-9][0-9]*\\.[0-9][0-9]*/'$npm_package_version'/' synapse_antispam/setup.py && git add synapse_antispam/setup.py && cat synapse_antispam/setup.py"
1919
},

β€Žsrc/utils.tsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ function patchMatrixClientForRetry() {
386386
// We need to retry.
387387
reject(err);
388388
} else {
389+
if (attempt >= MAX_REQUEST_ATTEMPTS) {
390+
LogService.warn('Mjolnir.client', `Retried request ${params.method} ${params.uri} ${attempt} times, giving up.`);
391+
}
389392
// No need-to-retry error? Lucky us!
390393
// Note that this may very well be an error, just not
391394
// one we need to retry.

β€Žtest/integration/banListTest.tsβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ describe('Test: We will not be able to ban ourselves via ACL.', function () {
231231

232232
describe('Test: ACL updates will batch when rules are added in succession.', function () {
233233
it('Will batch ACL updates if we spam rules into a BanList', async function () {
234-
this.timeout(180000)
235234
const mjolnir = config.RUNTIME.client!
236235
const serverName: string = new UserID(await mjolnir.getUserId()).domain
237236
const moderator = await newTestUser({ name: { contains: "moderator" }});
@@ -268,6 +267,8 @@ describe('Test: ACL updates will batch when rules are added in succession.', fun
268267
// Give them a bit of a spread over time.
269268
await new Promise(resolve => setTimeout(resolve, 5));
270269
}
270+
// give the events a chance to appear in the response to `/state`, since this is a problem.
271+
await new Promise(resolve => setTimeout(resolve, 2000));
271272

272273
// We do this because it should force us to wait until all the ACL events have been applied.
273274
// Even if that does mean the last few events will not go through batching...
@@ -364,9 +365,9 @@ describe('Test: unbaning entities via the BanList.', function () {
364365
})
365366
})
366367

367-
describe.only('Test: should apply bans to the most recently active rooms first', function () {
368+
describe('Test: should apply bans to the most recently active rooms first', function () {
368369
it('Applies bans to the most recently active rooms first', async function () {
369-
this.timeout(6000000000)
370+
this.timeout(180000)
370371
const mjolnir = config.RUNTIME.client!
371372
const serverName: string = new UserID(await mjolnir.getUserId()).domain
372373
const moderator = await newTestUser({ name: { contains: "moderator" }});

β€Žtest/integration/throttleTest.tsβ€Ž

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { getFirstReaction } from "./commands/commandUtils";
55

66
describe("Test: throttled users can function with Mjolnir.", function () {
77
it('throttled users survive being throttled by synapse', async function() {
8-
this.timeout(60000);
98
let throttledUser = await newTestUser({ name: { contains: "throttled" }, isThrottled: true });
109
let throttledUserId = await throttledUser.getUserId();
1110
let targetRoom = await throttledUser.createRoom();
1211
// send enough messages to hit the rate limit.
13-
await Promise.all([...Array(150).keys()].map((i) => throttledUser.sendMessage(targetRoom, {msgtype: 'm.text.', body: `Message #${i}`})));
12+
await Promise.all([...Array(25).keys()].map((i) => throttledUser.sendMessage(targetRoom, {msgtype: 'm.text.', body: `Message #${i}`})));
1413
let messageCount = 0;
15-
await getMessagesByUserIn(throttledUser, throttledUserId, targetRoom, 150, (events) => {
14+
await getMessagesByUserIn(throttledUser, throttledUserId, targetRoom, 25, (events) => {
1615
messageCount += events.length;
1716
});
18-
assert.equal(messageCount, 150, "There should have been 150 messages in this room");
17+
assert.equal(messageCount, 25, "There should have been 25 messages in this room");
1918
})
2019
})
2120

@@ -31,7 +30,6 @@ describe("Test: Mjolnir can still sync and respond to commands while throttled",
3130
})
3231

3332
it('Can still perform and respond to a redaction command', async function () {
34-
this.timeout(60000);
3533
// Create a few users and a room.
3634
let badUser = await newTestUser({ name: { contains: "spammer-needs-redacting" } });
3735
let badUserId = await badUser.getUserId();
@@ -45,12 +43,12 @@ describe("Test: Mjolnir can still sync and respond to commands while throttled",
4543
await badUser.joinRoom(targetRoom);
4644

4745
// Give Mjolnir some work to do and some messages to sync through.
48-
await Promise.all([...Array(100).keys()].map((i) => moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text.', body: `Irrelevant Message #${i}`})));
49-
await Promise.all([...Array(50).keys()].map(_ => moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: '!mjolnir status'})));
46+
await Promise.all([...Array(25).keys()].map((i) => moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text.', body: `Irrelevant Message #${i}`})));
47+
await Promise.all([...Array(25).keys()].map(_ => moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: '!mjolnir status'})));
5048

5149
await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir rooms add ${targetRoom}`});
5250

53-
await Promise.all([...Array(50).keys()].map((i) => badUser.sendMessage(targetRoom, {msgtype: 'm.text.', body: `Bad Message #${i}`})));
51+
await Promise.all([...Array(25).keys()].map((i) => badUser.sendMessage(targetRoom, {msgtype: 'm.text.', body: `Bad Message #${i}`})));
5452

5553
try {
5654
await moderator.start();
@@ -72,6 +70,6 @@ describe("Test: Mjolnir can still sync and respond to commands while throttled",
7270
}
7371
})
7472
});
75-
assert.equal(count, 51, "There should be exactly 51 events from the spammer in this room.");
73+
assert.equal(count, 26, "There should be exactly 26 events from the spammer in this room.");
7674
})
7775
})

0 commit comments

Comments
Β (0)