Skip to content

Commit

Permalink
fix(MongoInstance): kill the killerProcess on instance kill (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
skrtheboss authored and nodkz committed Jan 10, 2019
1 parent b59ed82 commit 545d098
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/util/MongoInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export default class MongodbInstance {
this.childProcess.kill();
});
}
if (this.killerProcess && !(this.killerProcess: any).killed) {
await new Promise(resolve => {
this.killerProcess.once(`exit`, resolve);
this.killerProcess.kill();
});
}
return this;
}

Expand Down
4 changes: 4 additions & 0 deletions src/util/__tests__/MongoInstance-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ describe('MongoInstance', () => {
binary: { version: 'latest' },
});
const pid: any = mongod.getPid();
const killerPid: any = mongod.killerProcess.pid;
expect(pid).toBeGreaterThan(0);
expect(killerPid).toBeGreaterThan(0);

function isPidRunning(p: number) {
try {
Expand All @@ -135,8 +137,10 @@ describe('MongoInstance', () => {
}

expect(isPidRunning(pid)).toBeTruthy();
expect(isPidRunning(killerPid)).toBeTruthy();
await mongod.kill();
expect(isPidRunning(pid)).toBeFalsy();
expect(isPidRunning(killerPid)).toBeFalsy();
});

it('should work with mongodb 4.0.3', async () => {
Expand Down

0 comments on commit 545d098

Please sign in to comment.