perf: reduce memory usage upon running server tests (#3949)

* perf: reduce memory usage upon running server tests

* perf: plug leaks in server/routes

* perf: plug leaks in server/scripts

* perf: plug leaks in server/policies

* perf: plug leaks in server/models

* perf: plug leaks in server/middlewares

* perf: plug leaks in server/commands

* fix: missing await on db.flush

* perf: plug leaks in server/queues

* chore: remove unused legacy funcs

* fix: await on db.flush

* perf: await on GC to run in between tests

* fix: remove db refs

* fix: revert embeds

* perf: plug leaks in shared/i18n
This commit is contained in:
Apoorv Mishra
2022-08-11 21:39:17 +05:30
committed by GitHub
parent 8e1f42a9cb
commit 0c51bfb899
68 changed files with 463 additions and 178 deletions

View File

@@ -7,13 +7,19 @@ import {
buildTeam,
buildDocument,
} from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import { getTestDatabase, seed } from "@server/test/support";
import slugify from "@server/utils/slugify";
import Collection from "./Collection";
import Document from "./Document";
beforeEach(() => flushdb());
beforeEach(jest.resetAllMocks);
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("#url", () => {
test("should return correct url for the collection", () => {

View File

@@ -6,11 +6,17 @@ import {
buildUser,
buildShare,
} from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import { getTestDatabase, seed } from "@server/test/support";
import slugify from "@server/utils/slugify";
beforeEach(() => flushdb());
beforeEach(jest.resetAllMocks);
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("#getSummary", () => {
test("should strip markdown", async () => {

View File

@@ -1,10 +1,16 @@
import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import CollectionGroup from "./CollectionGroup";
import GroupUser from "./GroupUser";
beforeEach(() => flushdb());
beforeEach(jest.resetAllMocks);
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("afterDestroy hook", () => {
test("should destroy associated group and collection join relations", async () => {

View File

@@ -1,9 +1,15 @@
import { buildDocument } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import Revision from "./Revision";
beforeEach(() => flushdb());
beforeEach(jest.resetAllMocks);
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("#findLatest", () => {
test("should return latest revision", async () => {

View File

@@ -1,7 +1,14 @@
import { buildTeam, buildCollection } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
beforeEach(() => flushdb());
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("collectionIds", () => {
it("should return non-private collection ids", async () => {

View File

@@ -1,8 +1,15 @@
import { buildAdmin, buildTeam } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import TeamDomain from "./TeamDomain";
beforeEach(() => flushdb());
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("team domain model", () => {
describe("create", () => {

View File

@@ -1,16 +1,21 @@
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import CollectionUser from "./CollectionUser";
import UserAuthentication from "./UserAuthentication";
beforeEach(() => flushdb());
const db = getTestDatabase();
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
});
afterAll(() => {
jest.useRealTimers();
db.disconnect();
});
beforeEach(db.flush);
describe("user model", () => {
describe("destroy", () => {
it("should delete user authentications", async () => {