mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-09-29 20:56:23 +00:00
pass Mjolnir around
This commit is contained in:
parent
082d998ec2
commit
d75b56c794
@ -1,6 +1,7 @@
|
|||||||
import { strict as assert } from "assert";
|
import { strict as assert } from "assert";
|
||||||
|
|
||||||
import { newTestUser } from "./clientHelper";
|
import { newTestUser } from "./clientHelper";
|
||||||
|
import { Mjolnir } from "../../src/Mjolnir";
|
||||||
import config from "../../src/config";
|
import config from "../../src/config";
|
||||||
import { getRequestFn, LogService, MatrixClient } from "matrix-bot-sdk";
|
import { getRequestFn, LogService, MatrixClient } from "matrix-bot-sdk";
|
||||||
import { createBanList, getFirstReaction } from "./commands/commandUtils";
|
import { createBanList, getFirstReaction } from "./commands/commandUtils";
|
||||||
@ -8,9 +9,9 @@ import { createBanList, getFirstReaction } from "./commands/commandUtils";
|
|||||||
/**
|
/**
|
||||||
* Get a copy of the rules from the ruleserver.
|
* Get a copy of the rules from the ruleserver.
|
||||||
*/
|
*/
|
||||||
async function currentRules(address: string, port: number): Promise<{ start: object, stop: object, since: string }> {
|
async function currentRules(mjolnir: Mjolnir): Promise<{ start: object, stop: object, since: string }> {
|
||||||
return await new Promise((resolve, reject) => getRequestFn()({
|
return await new Promise((resolve, reject) => getRequestFn()({
|
||||||
uri: `http://${address}:${port}/api/1/ruleserver/updates/`,
|
uri: `http://${mjolnir.config.web.address}:${mjolnir.config.web.port}/api/1/ruleserver/updates/`,
|
||||||
method: "GET"
|
method: "GET"
|
||||||
}, (error, response, body) => {
|
}, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -25,8 +26,8 @@ async function currentRules(address: string, port: number): Promise<{ start: obj
|
|||||||
* Wait for the rules to change as a result of the thunk. The returned promise will resolve when the rules being served have changed.
|
* Wait for the rules to change as a result of the thunk. The returned promise will resolve when the rules being served have changed.
|
||||||
* @param thunk Should cause the rules the RuleServer is serving to change some way.
|
* @param thunk Should cause the rules the RuleServer is serving to change some way.
|
||||||
*/
|
*/
|
||||||
async function waitForRuleChange(address: string, port: number, thunk): Promise<void> {
|
async function waitForRuleChange(mjolnir: Mjolnir, thunk): Promise<void> {
|
||||||
const initialRules = await currentRules(address, port);
|
const initialRules = await currentRules(mjolnir);
|
||||||
let rules = initialRules;
|
let rules = initialRules;
|
||||||
// We use JSON.stringify like this so that it is pretty printed in the log and human readable.
|
// We use JSON.stringify like this so that it is pretty printed in the log and human readable.
|
||||||
LogService.debug('policyConsumptionTest', `Rules before we wait for them to change: ${JSON.stringify(rules, null, 2)}`);
|
LogService.debug('policyConsumptionTest', `Rules before we wait for them to change: ${JSON.stringify(rules, null, 2)}`);
|
||||||
@ -35,7 +36,7 @@ async function waitForRuleChange(address: string, port: number, thunk): Promise<
|
|||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
setTimeout(resolve, 500);
|
setTimeout(resolve, 500);
|
||||||
})
|
})
|
||||||
rules = await currentRules(address, port);
|
rules = await currentRules(mjolnir);
|
||||||
};
|
};
|
||||||
// The problem is, we have no idea how long a consumer will take to process the changed rules.
|
// The problem is, we have no idea how long a consumer will take to process the changed rules.
|
||||||
// We know the pull peroid is 1 second though.
|
// We know the pull peroid is 1 second though.
|
||||||
@ -49,9 +50,7 @@ describe("Test: that policy lists are consumed by the associated synapse module"
|
|||||||
this.afterEach(async function () {
|
this.afterEach(async function () {
|
||||||
if(this.config.web.ruleServer.enabled) {
|
if(this.config.web.ruleServer.enabled) {
|
||||||
this.timeout(5000)
|
this.timeout(5000)
|
||||||
LogService.debug('policyConsumptionTest', `Rules at end of test ${JSON.stringify(await currentRules(
|
LogService.debug('policyConsumptionTest', `Rules at end of test ${JSON.stringify(await currentRules(this.mjolnir), null, 2)}`);
|
||||||
this.config.web.address, this.mjolnir.config.web.port
|
|
||||||
), null, 2)}`);
|
|
||||||
const mjolnir = config.RUNTIME.client!;
|
const mjolnir = config.RUNTIME.client!;
|
||||||
// Clear any state associated with the account.
|
// Clear any state associated with the account.
|
||||||
await mjolnir.setAccountData('org.matrix.mjolnir.watched_lists', {
|
await mjolnir.setAccountData('org.matrix.mjolnir.watched_lists', {
|
||||||
|
Loading…
Reference in New Issue
Block a user