Skip to content

Commit c91b703

Browse files
committed
fix(MongoInstance): fix resetting "isInstancePrimary" in the same line
1 parent 923aae6 commit c91b703

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/mongodb-memory-server-core/src/util/MongoInstance.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,7 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
542542
if (/\*\*\*aborting after/i.test(line)) {
543543
this.emit(MongoInstanceEvents.instanceError, 'Mongod internal error');
544544
}
545-
if (/transition to primary complete; database writes are now permitted/i.test(line)) {
546-
this.isInstancePrimary = true;
547-
this.debug('stdoutHandler: emitting "instancePrimary"');
548-
this.emit(MongoInstanceEvents.instancePrimary);
549-
}
545+
// this case needs to be infront of "transition to primary complete", otherwise it might reset "isInstancePrimary" to "false"
550546
if (/transition to \w+ from \w+/i.test(line)) {
551547
const state = /transition to (\w+) from \w+/i.exec(line)?.[1] ?? 'UNKNOWN';
552548
this.emit(MongoInstanceEvents.instanceReplState, state);
@@ -555,6 +551,11 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
555551
this.isInstancePrimary = false;
556552
}
557553
}
554+
if (/transition to primary complete; database writes are now permitted/i.test(line)) {
555+
this.isInstancePrimary = true;
556+
this.debug('stdoutHandler: emitting "instancePrimary"');
557+
this.emit(MongoInstanceEvents.instancePrimary);
558+
}
558559
}
559560
}
560561

0 commit comments

Comments
 (0)