File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -313,12 +313,12 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
313313 }
314314
315315 if ( ! isNullOrUndefined ( this . mongodProcess ) ) {
316- // try to run "replSetStepDown " before running "killProcess" (gracefull "SIGINT")
317- // running "&& this.isInstancePrimary" otherwise "replSetStepDown" will fail with "MongoError: not primary so can't step down"
318- if ( this . isReplSet && this . isInstancePrimary ) {
316+ // try to run "shutdown " before running "killProcess" (gracefull "SIGINT")
317+ // using this, otherwise on windows nodejs will handle "SIGINT" & "SIGTERM" & "SIGKILL" the same (instant exit)
318+ if ( this . isReplSet ) {
319319 let con : MongoClient | undefined ;
320320 try {
321- this . debug ( 'stop: trying replSetStepDown ' ) ;
321+ this . debug ( 'stop: trying shutdownServer ' ) ;
322322 const port = this . instanceOpts . port ;
323323 const ip = this . instanceOpts . ip ;
324324 assertion (
@@ -336,7 +336,8 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
336336 } ) ;
337337
338338 const admin = con . db ( 'admin' ) ; // just to ensure it is actually the "admin" database
339- await admin . command ( { replSetStepDown : 1 , force : true } ) ;
339+ // "timeoutSecs" is set to "1" otherwise it will take at least "10" seconds to stop (very long tests)
340+ await admin . command ( { shutdown : 1 , force : true , timeoutSecs : 1 } ) ;
340341 } catch ( err ) {
341342 // Quote from MongoDB Documentation (https://docs.mongodb.com/manual/reference/command/replSetStepDown/#client-connections):
342343 // > Starting in MongoDB 4.2, replSetStepDown command no longer closes all client connections.
You can’t perform that action at this time.
0 commit comments