Skip to content

Commit

Permalink
test(MongoMemoryReplSet): better cleanup created temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Jun 9, 2023
1 parent 4d22ce5 commit bd18403
Showing 1 changed file with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop();

Expand All @@ -568,9 +566,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false });

Expand Down Expand Up @@ -608,9 +604,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false, force: false });

Expand All @@ -635,9 +629,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false });
await replSet.cleanup();
Expand All @@ -653,9 +645,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false });
await replSet.cleanup({ doCleanup: true, force: false });
Expand All @@ -670,9 +660,7 @@ describe('MongoMemoryReplSet', () => {

await replSet.start();

const cleanupInstance1Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance1Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false });
await replSet.cleanup({ doCleanup: true, force: true });
Expand Down Expand Up @@ -702,9 +690,7 @@ describe('MongoMemoryReplSet', () => {
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });

const cleanupSpy = jest.spyOn(replSet, 'cleanup');
const cleanupInstance0Spy = jest
.spyOn(replSet.servers[0], 'cleanup')
.mockResolvedValue(void 0);
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');

await replSet.stop({ doCleanup: false });
await replSet.cleanup({ doCleanup: true, force: true });
Expand Down Expand Up @@ -754,5 +740,10 @@ describe('MongoMemoryReplSet', () => {
utils.assertion(!utils.isNullOrUndefined(instanceInfo));
expect(instanceInfo.instance).toBeDefined();
expect(instanceInfo?.launchTimeout).toStrictEqual(2000);

await utils.removeDir(
// @ts-expect-error "_instanceInfo" is protected
replSet.servers[0]._instanceInfo.tmpDir!
); // manual cleanup
});
});

0 comments on commit bd18403

Please sign in to comment.