Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reduce memory usage upon running server tests #3949

Merged
merged 15 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions .jestconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"<rootDir>/server/test/setup.ts"
],
"testEnvironment": "node",
"runner": "@getoutline/jest-runner-serial"
"runner": "@getoutline/jest-runner-serial",
"detectLeaks": true
tommoor marked this conversation as resolved.
Show resolved Hide resolved
},
{
"displayName": "app",
Expand Down Expand Up @@ -56,6 +57,9 @@
"setupFiles": [
"<rootDir>/__mocks__/console.js"
],
"setupFilesAfterEnv": [
"<rootDir>/shared/test/setup.ts"
],
"testEnvironment": "node"
},
{
Expand All @@ -79,4 +83,4 @@
}
}
]
}
}
10 changes: 6 additions & 4 deletions server/commands/accountProvisioner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { TeamDomain } from "@server/models";
import Collection from "@server/models/Collection";
import UserAuthentication from "@server/models/UserAuthentication";
import { buildUser, buildTeam } from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import { getTestDatabase, seed } from "@server/test/support";
import accountProvisioner from "./accountProvisioner";

beforeEach(() => {
return flushdb();
});
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("accountProvisioner", () => {
const ip = "127.0.0.1";
Expand Down
9 changes: 7 additions & 2 deletions server/commands/documentImporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import path from "path";
import fs from "fs-extra";
import Attachment from "@server/models/Attachment";
import { buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import documentImporter from "./documentImporter";

jest.mock("../utils/s3");
beforeEach(() => flushdb());

const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("documentImporter", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/documentMover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import {
buildCollection,
buildUser,
} from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import { getTestDatabase, seed } from "@server/test/support";
import documentMover from "./documentMover";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("documentMover", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/documentPermanentDeleter.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { subDays } from "date-fns";
import { Attachment, Document } from "@server/models";
import { buildAttachment, buildDocument } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import documentPermanentDeleter from "./documentPermanentDeleter";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("documentPermanentDeleter", () => {
it("should destroy documents", async () => {
Expand Down
8 changes: 6 additions & 2 deletions server/commands/documentUpdater.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { sequelize } from "@server/database/sequelize";
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import documentUpdater from "./documentUpdater";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("documentUpdater", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/fileOperationDeleter.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { FileOperation } from "@server/models";
import { buildAdmin, buildFileOperation } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import fileOperationDeleter from "./fileOperationDeleter";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("fileOperationDeleter", () => {
const ip = "127.0.0.1";
Expand Down
9 changes: 7 additions & 2 deletions server/commands/pinCreator.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import pinCreator from "./pinCreator";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("pinCreator", () => {
const ip = "127.0.0.1";

Expand Down
9 changes: 7 additions & 2 deletions server/commands/pinDestroyer.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Pin, Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import pinDestroyer from "./pinDestroyer";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("pinCreator", () => {
const ip = "127.0.0.1";

Expand Down
8 changes: 6 additions & 2 deletions server/commands/revisionCreator.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import revisionCreator from "./revisionCreator";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("revisionCreator", () => {
const ip = "127.0.0.1";
Expand Down
9 changes: 7 additions & 2 deletions server/commands/starCreator.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { sequelize } from "@server/database/sequelize";
import { Star, Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import starCreator from "./starCreator";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("starCreator", () => {
const ip = "127.0.0.1";

Expand Down
8 changes: 6 additions & 2 deletions server/commands/starDestroyer.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Star, Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import starDestroyer from "./starDestroyer";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("starDestroyer", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/starUpdater.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Star, Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import starUpdater from "./starUpdater";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("starUpdater", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/teamPermanentDeleter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import {
buildTeam,
buildDocument,
} from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import teamPermanentDeleter from "./teamPermanentDeleter";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("teamPermanentDeleter", () => {
it("should destroy related data", async () => {
Expand Down
8 changes: 6 additions & 2 deletions server/commands/teamProvisioner.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import env from "@server/env";
import TeamDomain from "@server/models/TeamDomain";
import { buildTeam, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import teamProvisioner from "./teamProvisioner";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("teamProvisioner", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/userDestroyer.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { buildUser, buildAdmin } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import userDestroyer from "./userDestroyer";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("userDestroyer", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/userInviter.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import userInviter from "./userInviter";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("userInviter", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/userProvisioner.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { v4 as uuidv4 } from "uuid";
import { TeamDomain } from "@server/models";
import { buildUser, buildTeam, buildInvite } from "@server/test/factories";
import { flushdb, seed } from "@server/test/support";
import { getTestDatabase, seed } from "@server/test/support";
import userProvisioner from "./userProvisioner";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("userProvisioner", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/commands/userSuspender.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import GroupUser from "@server/models/GroupUser";
import { buildGroup, buildAdmin, buildUser } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import userSuspender from "./userSuspender";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("userSuspender", () => {
const ip = "127.0.0.1";
Expand Down
8 changes: 6 additions & 2 deletions server/middlewares/authentication.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import randomstring from "randomstring";
import ApiKey from "@server/models/ApiKey";
import { buildUser, buildTeam } from "@server/test/factories";
import { flushdb } from "@server/test/support";
import { getTestDatabase } from "@server/test/support";
import auth from "./authentication";

beforeEach(() => flushdb());
const db = getTestDatabase();

afterAll(db.disconnect);

beforeEach(db.flush);

describe("Authentication middleware", () => {
describe("with JWT", () => {
Expand Down
12 changes: 9 additions & 3 deletions server/models/Collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
12 changes: 9 additions & 3 deletions server/models/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down