Fix bad teardowns that hang in tests. (#202)

* Fix bad teardowns and hanging test.
This commit is contained in:
Gnuxie 2022-01-28 11:03:20 +00:00 committed by GitHub
parent 0cde70e846
commit e52b59df6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -90,7 +90,7 @@ async function registerNewTestUser(options: RegistrationOptions) {
username = `mjolnir-test-user-${options.name.contains}${Math.floor(Math.random() * 100000)}` username = `mjolnir-test-user-${options.name.contains}${Math.floor(Math.random() * 100000)}`
} }
try { try {
await registerUser(username, username, username, options.isAdmin); await registerUser(username, username, username, Boolean(options.isAdmin));
return username; return username;
} catch (e) { } catch (e) {
if (e?.body?.errcode === 'M_USER_IN_USE') { if (e?.body?.errcode === 'M_USER_IN_USE') {

View File

@ -23,7 +23,7 @@ import * as crypto from "crypto";
const targetEventId = await targetEventThunk(); const targetEventId = await targetEventThunk();
for (let event of reactionEvents) { for (let event of reactionEvents) {
const in_reply_to = event.content['m.relates_to']?.['m.in_reply_to']; const in_reply_to = event.content['m.relates_to']?.['m.in_reply_to'];
if (in_reply_to.event_id === targetEventId) { if (in_reply_to?.event_id === targetEventId) {
return event; return event;
} }
} }
@ -70,7 +70,7 @@ export async function getFirstReaction(client: MatrixClient, targetRoom: string,
const targetEventId = await targetEventThunk(); const targetEventId = await targetEventThunk();
for (let event of reactionEvents) { for (let event of reactionEvents) {
const relates_to = event.content['m.relates_to']; const relates_to = event.content['m.relates_to'];
if (relates_to.event_id === targetEventId && relates_to.key === reactionKey) { if (relates_to?.event_id === targetEventId && relates_to?.key === reactionKey) {
return event; return event;
} }
} }
@ -79,7 +79,7 @@ export async function getFirstReaction(client: MatrixClient, targetRoom: string,
if (roomId !== targetRoom) return; if (roomId !== targetRoom) return;
if (event.type !== 'm.reaction') return; if (event.type !== 'm.reaction') return;
const relates_to = event.content['m.relates_to']; const relates_to = event.content['m.relates_to'];
if (relates_to.event_id === targetEventId && relates_to.key === reactionKey) { if (relates_to?.event_id === targetEventId && relates_to?.key === reactionKey) {
resolve(event) resolve(event)
} }
} }

View File

@ -7,6 +7,9 @@ import { LogService } from "matrix-bot-sdk";
import { getFirstReaction } from "./commandUtils"; import { getFirstReaction } from "./commandUtils";
describe("Test: The redaction command", function () { describe("Test: The redaction command", function () {
// If a test has a timeout while awaitng on a promise then we never get given control back.
afterEach(function() { this.moderator?.stop(); });
it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function() { it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function() {
this.timeout(60000); this.timeout(60000);
// Create a few users and a room. // Create a few users and a room.
@ -51,6 +54,7 @@ import { getFirstReaction } from "./commandUtils";
}) })
}); });
}) })
it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id in multiple rooms.', async function() { it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id in multiple rooms.', async function() {
this.timeout(60000); this.timeout(60000);
// Create a few users and a room. // Create a few users and a room.

View File

@ -24,6 +24,9 @@ describe("Test: Mjolnir can still sync and respond to commands while throttled",
await resetRatelimitForUser(await this.mjolnir.client.getUserId()) await resetRatelimitForUser(await this.mjolnir.client.getUserId())
}) })
afterEach(async function() { afterEach(async function() {
// If a test has a timeout while awaitng on a promise then we never get given control back.
this.moderator?.stop();
await overrideRatelimitForUser(await this.mjolnir.client.getUserId()); await overrideRatelimitForUser(await this.mjolnir.client.getUserId());
}) })