Skip to content

Commit 46e1054

Browse files
authored
Merge pull request #926 from the-draupnir-project/gnuxie/weirdo-tests
Improvements to integration tests
2 parents 283a50d + 5afd97c commit 46e1054

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/DraupnirBotMode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { ResultError } from "@gnuxie/typescript-result";
4848
import { SafeModeCause, SafeModeReason } from "./safemode/SafeModeCause";
4949
import { SafeModeBootOption } from "./safemode/BootOption";
5050
import { TopLevelStores } from "./backingstore/DraupnirStores";
51+
import { patchMatrixClient } from "./utils";
5152

5253
const log = new Logger("DraupnirBotMode");
5354

@@ -111,6 +112,7 @@ export class DraupnirBotModeToggle implements BotModeTogle {
111112
config: IConfig,
112113
stores: TopLevelStores
113114
): Promise<DraupnirBotModeToggle> {
115+
patchMatrixClient();
114116
const clientUserID = await client.getUserId();
115117
if (!isStringUserID(clientUserID)) {
116118
throw new TypeError(`${clientUserID} is not a valid mxid`);

src/appservice/AppService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
} from "@the-draupnir-project/matrix-basic-types";
5050
import { SqliteRoomStateBackingStore } from "../backingstore/better-sqlite3/SqliteRoomStateBackingStore";
5151
import { TopLevelStores } from "../backingstore/DraupnirStores";
52+
import { patchMatrixClient } from "../utils";
5253

5354
const log = new Logger("AppService");
5455
/**
@@ -230,6 +231,7 @@ export class MjolnirAppService {
230231
registrationFilePath: string
231232
): Promise<MjolnirAppService> {
232233
Logger.configure(config.logging ?? { console: "debug" });
234+
patchMatrixClient();
233235
const dataStore = new PgDataStore(config.db.connectionString);
234236
await dataStore.init();
235237
const eventDecoder = DefaultEventDecoder;

src/config.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,19 @@ function getConfigMeta(): NonNullable<IConfig["configMeta"]> {
321321
};
322322
}
323323

324+
let configHookExitDump: undefined | (() => void) = undefined;
325+
326+
function registerConfigExitHook(config: IConfig): void {
327+
if (configHookExitDump) {
328+
return;
329+
}
330+
configHookExitDump = () => {
331+
logNonDefaultConfiguration(config);
332+
logConfigMeta(config);
333+
};
334+
process.on("exit", configHookExitDump);
335+
}
336+
324337
/**
325338
* @returns The users's raw config, deep copied over the `defaultConfig`.
326339
*/
@@ -349,10 +362,7 @@ function readConfigSource(): IConfig {
349362
unknownProperties
350363
);
351364
}
352-
process.on("exit", () => {
353-
logNonDefaultConfiguration(config);
354-
logConfigMeta(config);
355-
});
365+
registerConfigExitHook(config);
356366
return config;
357367
}
358368

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from "matrix-bot-sdk";
2121
import { StoreType } from "@matrix-org/matrix-sdk-crypto-nodejs";
2222
import { configRead as configRead, getStoragePath } from "./config";
23-
import { initializeSentry, patchMatrixClient } from "./utils";
23+
import { initializeSentry } from "./utils";
2424
import { DraupnirBotModeToggle } from "./DraupnirBotMode";
2525
import { SafeMatrixEmitterWrapper } from "matrix-protection-suite-for-matrix-bot-sdk";
2626
import { DefaultEventDecoder } from "matrix-protection-suite";
@@ -81,7 +81,6 @@ void (async function () {
8181
storage
8282
);
8383
}
84-
patchMatrixClient();
8584
const eventDecoder = DefaultEventDecoder;
8685
const stores = makeTopLevelStores(storagePath, eventDecoder, {
8786
isRoomStateBackingStoreEnabled:

test/integration/fixtures.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ async function cleanUpTopLevelStores(storagePath: string) {
6060
}
6161
})
6262
);
63+
//
6364
}
6465

6566
// When Draupnir starts (src/index.ts) it clobbers the config by resolving the management room
@@ -106,6 +107,8 @@ export const mochaHooks = {
106107
await this.toggle?.stopEverything();
107108
draupnirClient()?.stop();
108109
this.stores?.dispose();
110+
// With regret, please see https://github.com/the-draupnir-project/Draupnir/issues/927.
111+
await new Promise((resolve) => setTimeout(resolve, 50));
109112
if (this.draupnir !== undefined) {
110113
await Promise.all([
111114
this.draupnir.client.setAccountData(

0 commit comments

Comments
 (0)