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 Aug 17, 2023
1 parent ead7958 commit 2cbfb58
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(false);

Expand All @@ -593,9 +589,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 @@ -620,9 +614,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 @@ -638,9 +630,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(false);
Expand All @@ -655,9 +645,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(true);
Expand All @@ -671,9 +659,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 @@ -723,5 +709,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 2cbfb58

Please sign in to comment.