Skip to content

Commit 545d098

Browse files
skrthebossnodkz
authored andcommitted
fix(MongoInstance): kill the killerProcess on instance kill (#129)
1 parent b59ed82 commit 545d098

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/util/MongoInstance.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ export default class MongodbInstance {
111111
this.childProcess.kill();
112112
});
113113
}
114+
if (this.killerProcess && !(this.killerProcess: any).killed) {
115+
await new Promise(resolve => {
116+
this.killerProcess.once(`exit`, resolve);
117+
this.killerProcess.kill();
118+
});
119+
}
114120
return this;
115121
}
116122

src/util/__tests__/MongoInstance-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ describe('MongoInstance', () => {
124124
binary: { version: 'latest' },
125125
});
126126
const pid: any = mongod.getPid();
127+
const killerPid: any = mongod.killerProcess.pid;
127128
expect(pid).toBeGreaterThan(0);
129+
expect(killerPid).toBeGreaterThan(0);
128130

129131
function isPidRunning(p: number) {
130132
try {
@@ -135,8 +137,10 @@ describe('MongoInstance', () => {
135137
}
136138

137139
expect(isPidRunning(pid)).toBeTruthy();
140+
expect(isPidRunning(killerPid)).toBeTruthy();
138141
await mongod.kill();
139142
expect(isPidRunning(pid)).toBeFalsy();
143+
expect(isPidRunning(killerPid)).toBeFalsy();
140144
});
141145

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

0 commit comments

Comments
 (0)