@@ -195,6 +195,7 @@ export class MongoInstance extends EventEmitter {
195195 * @fires MongoInstance#instanceStarted
196196 */
197197 async run ( ) : Promise < this> {
198+ this . debug ( 'run' ) ;
198199 this . isInstancePrimary = false ;
199200 this . isInstanceReady = false ;
200201 this . isReplSet = false ;
@@ -217,11 +218,13 @@ export class MongoInstance extends EventEmitter {
217218 ) ;
218219 throw err ;
219220 }
221+ this . debug ( 'run: Starting Processes' ) ;
220222 this . childProcess = this . _launchMongod ( mongoBin ) ;
221223 this . killerProcess = this . _launchKiller ( process . pid , this . childProcess . pid ) ;
222224
223225 await launch ;
224226 this . emit ( MongoInstanceEvents . instanceStarted ) ;
227+ this . debug ( 'run: Processes Started' ) ;
225228
226229 return this ;
227230 }
@@ -230,7 +233,7 @@ export class MongoInstance extends EventEmitter {
230233 * Shutdown all related processes (Mongod Instance & Killer Process)
231234 */
232235 async kill ( ) : Promise < MongoInstance > {
233- this . debug ( 'Called MongoInstance .kill():' ) ;
236+ this . debug ( 'kill: Called .kill():' ) ;
234237
235238 if ( ! isNullOrUndefined ( this . childProcess ) ) {
236239 // try to run "replSetStepDown" before running "killProcess" (gracefull "SIGINT")
@@ -282,16 +285,16 @@ export class MongoInstance extends EventEmitter {
282285 await killProcess ( this . childProcess , 'childProcess' ) ;
283286 this . childProcess = undefined ; // reset reference to the childProcess for "mongod"
284287 } else {
285- this . debug ( '- childProcess: nothing to shutdown, skipping. ' ) ;
288+ this . debug ( 'kill: childProcess: nothing to shutdown, skipping' ) ;
286289 }
287290 if ( ! isNullOrUndefined ( this . killerProcess ) ) {
288291 await killProcess ( this . killerProcess , 'killerProcess' ) ;
289292 this . killerProcess = undefined ; // reset reference to the childProcess for "mongo_killer"
290293 } else {
291- this . debug ( '- killerProcess: nothing to shutdown, skipping. ' ) ;
294+ this . debug ( 'kill: killerProcess: nothing to shutdown, skipping' ) ;
292295 }
293296
294- this . debug ( 'Instance Finished Shutdown' ) ;
297+ this . debug ( 'kill: Instance Finished Shutdown' ) ;
295298
296299 return this ;
297300 }
@@ -302,6 +305,7 @@ export class MongoInstance extends EventEmitter {
302305 * @fires MongoInstance#instanceLaunched
303306 */
304307 _launchMongod ( mongoBin : string ) : ChildProcess {
308+ this . debug ( '_launchMongod: Launching Mongod Process' ) ;
305309 const childProcess = spawn ( resolve ( mongoBin ) , this . prepareCommandArgs ( ) , {
306310 ...this . spawnOpts ,
307311 stdio : 'pipe' , // ensure that stdio is always an pipe, regardless of user input
@@ -322,12 +326,14 @@ export class MongoInstance extends EventEmitter {
322326
323327 /**
324328 * Spawn an child to kill the parent and the mongod instance if both are Dead
325- * @param parentPid Parent to kill
329+ * @param parentPid Parent nodejs process
326330 * @param childPid Mongod process to kill
327331 * @fires MongoInstance#killerLaunched
328332 */
329333 _launchKiller ( parentPid : number , childPid : number ) : ChildProcess {
330- this . debug ( `Called MongoInstance._launchKiller(parent: ${ parentPid } , child: ${ childPid } ):` ) ;
334+ this . debug (
335+ `_launchKiller: Launching Killer Process (parent: ${ parentPid } , child: ${ childPid } )`
336+ ) ;
331337 // spawn process which kills itself and mongo process if current process is dead
332338 const killer = fork (
333339 path . resolve ( __dirname , '../../scripts/mongo_killer.js' ) ,
@@ -393,8 +399,8 @@ export class MongoInstance extends EventEmitter {
393399 * @fires MongoInstance#instanceReplState
394400 */
395401 stdoutHandler ( message : string | Buffer ) : void {
396- const line : string = message . toString ( ) ;
397- this . debug ( `STDOUT: ${ line } ` ) ;
402+ const line : string = message . toString ( ) . trim ( ) ; // trimming to remove extra new lines and spaces around the message
403+ this . debug ( `STDOUT: "" ${ line } "" ` ) ; // denoting the STDOUT string with double quotes, because the stdout might also use quotes
398404 this . emit ( MongoInstanceEvents . instanceSTDOUT , line ) ;
399405
400406 if ( / w a i t i n g f o r c o n n e c t i o n s / i. test ( line ) ) {
0 commit comments