@@ -67,11 +67,20 @@ export function assertion(cond: unknown, error?: Error): asserts cond {
6767 * Kill an ChildProcess
6868 * @param childprocess The Process to kill
6969 * @param name the name used in the logs
70+ * @param mongodPort the port for the mongod process (for easier logging)
7071 */
71- export async function killProcess ( childprocess : ChildProcess , name : string ) : Promise < void > {
72+ export async function killProcess (
73+ childprocess : ChildProcess ,
74+ name : string ,
75+ mongodPort : number | undefined
76+ ) : Promise < void > {
77+ function ilog ( msg : string ) {
78+ log ( `Mongo[${ mongodPort || 'unknown' } ] killProcess: ${ msg } ` ) ;
79+ }
80+
7281 // check if the childProcess (via PID) is still alive (found thanks to https://github.com/nodkz/mongodb-memory-server/issues/411)
7382 if ( ! isAlive ( childprocess . pid ) ) {
74- log ( "killProcess: given childProcess's PID was not alive anymore" ) ;
83+ ilog ( "killProcess: given childProcess's PID was not alive anymore" ) ;
7584
7685 return ;
7786 }
@@ -82,7 +91,7 @@ export async function killProcess(childprocess: ChildProcess, name: string): Pro
8291 const timeoutTime = 1000 * 10 ;
8392 await new Promise < void > ( ( res , rej ) => {
8493 let timeout = setTimeout ( ( ) => {
85- log ( 'killProcess: timeout triggered, trying SIGKILL' ) ;
94+ ilog ( 'killProcess: timeout triggered, trying SIGKILL' ) ;
8695
8796 if ( ! debug . enabled ( 'MongoMS:utils' ) ) {
8897 console . warn (
@@ -93,16 +102,16 @@ export async function killProcess(childprocess: ChildProcess, name: string): Pro
93102
94103 childprocess . kill ( 'SIGKILL' ) ;
95104 timeout = setTimeout ( ( ) => {
96- log ( 'killProcess: timeout triggered again, rejecting' ) ;
105+ ilog ( 'killProcess: timeout triggered again, rejecting' ) ;
97106 rej ( new Error ( `Process "${ name } " didnt exit, enable debug for more information.` ) ) ;
98107 } , timeoutTime ) ;
99108 } , timeoutTime ) ;
100109 childprocess . once ( `exit` , ( code , signal ) => {
101- log ( `killProcess: ${ name } : got exit signal, Code: ${ code } , Signal: ${ signal } ` ) ;
110+ ilog ( `killProcess: ${ name } : got exit signal, Code: ${ code } , Signal: ${ signal } ` ) ;
102111 clearTimeout ( timeout ) ;
103112 res ( ) ;
104113 } ) ;
105- log ( `killProcess: ${ name } : sending "SIGINT"` ) ;
114+ ilog ( `killProcess: ${ name } : sending "SIGINT"` ) ;
106115 childprocess . kill ( 'SIGINT' ) ;
107116 } ) ;
108117}
0 commit comments