mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Fix improper closing of resources in integration tests.
This commit is contained in:
parent
51e601603d
commit
0bd666f168
@ -14,7 +14,7 @@
|
||||
"start:dev": "yarn build && node --async-stack-traces lib/index.js",
|
||||
"test": "ts-mocha --project ./tsconfig.json test/commands/**/*.ts",
|
||||
"test:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\"",
|
||||
"test:appservice:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --exit --timeout 300000 --project ./tsconfig.json \"test/appservice/integration/**/*Test.ts\"",
|
||||
"test:appservice:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --timeout 300000 --project ./tsconfig.json \"test/appservice/integration/**/*Test.ts\"",
|
||||
"test:manual": "NODE_ENV=harness ts-node test/integration/manualLaunchScript.ts",
|
||||
"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"
|
||||
},
|
||||
|
@ -2,9 +2,11 @@ import request from "request";
|
||||
import express from "express";
|
||||
import * as bodyParser from "body-parser";
|
||||
import { MjolnirManager } from "./MjolnirManager";
|
||||
import * as http from "http";
|
||||
|
||||
export class Api {
|
||||
private httpdConfig: express.Express = express();
|
||||
private httpServer?: http.Server;
|
||||
|
||||
constructor(
|
||||
private homeserver: string,
|
||||
@ -34,7 +36,19 @@ export class Api {
|
||||
});
|
||||
}
|
||||
|
||||
public async close() {
|
||||
return await new Promise((resolve, reject) => {
|
||||
if (!this.httpServer) {
|
||||
throw new TypeError("Server was never started");
|
||||
}
|
||||
this.httpServer.close(error => error ? reject(error) : resolve(undefined))
|
||||
});
|
||||
}
|
||||
|
||||
public start(port: number) {
|
||||
if (this.httpServer) {
|
||||
throw new TypeError("server already started");
|
||||
}
|
||||
this.httpdConfig.use(bodyParser.json());
|
||||
|
||||
this.httpdConfig.get("/get", this.pathGet.bind(this));
|
||||
@ -42,7 +56,7 @@ export class Api {
|
||||
this.httpdConfig.post("/create", this.pathCreate.bind(this));
|
||||
this.httpdConfig.post("/join", this.pathJoin.bind(this));
|
||||
|
||||
this.httpdConfig.listen(port);
|
||||
this.httpServer = this.httpdConfig.listen(port);
|
||||
}
|
||||
|
||||
private async pathGet(req: express.Request, response: express.Response) {
|
||||
|
@ -100,6 +100,7 @@ export class MjolnirAppService {
|
||||
public async close(): Promise<void> {
|
||||
await this.bridge.close();
|
||||
await this.dataStore.close();
|
||||
await this.api.close();
|
||||
}
|
||||
|
||||
public static generateRegistration(reg: AppServiceRegistration, callback: (finalRegisration: AppServiceRegistration) => void) {
|
||||
|
@ -1,28 +1,24 @@
|
||||
import { readTestConfig, setupHarness } from "../utils/harness";
|
||||
import { isPolicyRoom, readTestConfig, setupHarness } from "../utils/harness";
|
||||
import { newTestUser } from "../../integration/clientHelper";
|
||||
import { getFirstReply } from "../../integration/commands/commandUtils";
|
||||
import { MatrixClient } from "matrix-bot-sdk";
|
||||
import { MjolnirAppService } from "../../../src/appservice/AppService";
|
||||
import PolicyList from "../../../src/models/PolicyList";
|
||||
import { CreateEvent } from "matrix-bot-sdk";
|
||||
import { doesNotMatch } from "assert";
|
||||
|
||||
interface Context extends Mocha.Context {
|
||||
user?: MatrixClient,
|
||||
appservice?: MjolnirAppService
|
||||
}
|
||||
|
||||
afterEach(function(this: Context) {
|
||||
this.user?.stop();
|
||||
// something still runs, and i'm not sure what? -- ignoring with --exit.
|
||||
this.appservice?.close();
|
||||
});
|
||||
|
||||
async function isPolicyRoom(user: MatrixClient, roomId: string): Promise<boolean> {
|
||||
const createEvent = new CreateEvent(await user.getRoomStateEvent(roomId, "m.room.create", ""));
|
||||
return PolicyList.ROOM_TYPE_VARIANTS.includes(createEvent.type);
|
||||
}
|
||||
|
||||
describe("Test that the app service can provision a mjolnir on invite of the appservice bot", function () {
|
||||
afterEach(function(this: Context) {
|
||||
this.user?.stop();
|
||||
if (this.appservice) {
|
||||
return this.appservice.close();
|
||||
} else {
|
||||
console.warn("Missing Appservice in this context, so cannot stop it.")
|
||||
}
|
||||
});
|
||||
it("", async function (this: Context) {
|
||||
const config = readTestConfig();
|
||||
this.appservice = await setupHarness();
|
||||
|
@ -4,6 +4,8 @@ import { ensureAliasedRoomExists } from "../../integration/mjolnirSetupUtils";
|
||||
import { read as configRead, IConfig } from "../../../src/appservice/config/config";
|
||||
import { PgDataStore } from "../../../src/appservice/datastore";
|
||||
import { newTestUser } from "../../integration/clientHelper";
|
||||
import PolicyList from "../../../src/models/PolicyList";
|
||||
import { CreateEvent, MatrixClient } from "matrix-bot-sdk";
|
||||
|
||||
export function readTestConfig(): IConfig {
|
||||
return configRead(path.join(__dirname, "../../../src/appservice/config/config.harness.yaml"));
|
||||
@ -20,3 +22,9 @@ export async function setupHarness(): Promise<MjolnirAppService> {
|
||||
await appservice.start(9000);
|
||||
return appservice;
|
||||
}
|
||||
|
||||
export async function isPolicyRoom(user: MatrixClient, roomId: string): Promise<boolean> {
|
||||
const createEvent = new CreateEvent(await user.getRoomStateEvent(roomId, "m.room.create", ""));
|
||||
return PolicyList.ROOM_TYPE_VARIANTS.includes(createEvent.type);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user