You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/hydrooj/test/db.ts

28 lines
855 B
TypeScript

import cluster from 'cluster';
import 'hydrooj/src/loader';
import * as bus from 'hydrooj/src/service/bus';
4 years ago
jest.mock('hydrooj/src/service/db');
export async function connect() {
const db = require('hydrooj/src/service/db');
await db.start({});
const scripts = require('hydrooj/src/upgrade').default;
let dbVer = 0;
const expected = scripts.length;
while (dbVer < expected) {
const func = scripts[dbVer];
dbVer++;
if (typeof func !== 'function' || func.toString().includes('_FRESH_INSTALL_IGNORE')) continue;
// eslint-disable-next-line no-await-in-loop
await func();
}
4 years ago
}
export async function dispose() {
const db = require('hydrooj/src/service/db');
await db.stop();
bus.emit('app/exit');
for (const key in cluster.workers) cluster.workers[key].destroy('SIGINT');
4 years ago
}