Skip to content

Commit 923aae6

Browse files
committed
fix(MongoInstance): change "instanceReplState" to get triggered on "transition"
1 parent 0bbc346 commit 923aae6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,8 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
547547
this.debug('stdoutHandler: emitting "instancePrimary"');
548548
this.emit(MongoInstanceEvents.instancePrimary);
549549
}
550-
if (/member [\d\.:]+ is now in state \w+/i.test(line)) {
551-
// "[\d\.:]+" matches "0.0.0.0:0000" (IP:PORT)
552-
const state = /member [\d\.:]+ is now in state (\w+)/i.exec(line)?.[1] ?? 'UNKNOWN';
550+
if (/transition to \w+ from \w+/i.test(line)) {
551+
const state = /transition to (\w+) from \w+/i.exec(line)?.[1] ?? 'UNKNOWN';
553552
this.emit(MongoInstanceEvents.instanceReplState, state);
554553

555554
if (state !== 'PRIMARY') {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ describe('MongodbInstance', () => {
358358
it('should emit "instanceReplState" when member state is changed', () => {
359359
// actual line copied from mongod 4.0.14
360360
const line =
361-
'STDOUT: 2020-09-30T19:41:48.388+0200 I REPL [replexec-0] Member 127.0.0.1:34765 is now in state STARTUP';
361+
'2021-08-27T18:44:01.4895064Z 2021-08-27T18:44:01.471+0000 I REPL [replication-1] transition to RECOVERING from STARTUP2';
362362

363363
mongod.isInstancePrimary = true;
364364
mongod.stdoutHandler(line);
365365

366366
expect(events.size).toEqual(2);
367367
expect(events.get(MongoInstanceEvents.instanceSTDOUT)).toEqual(line);
368-
expect(events.get(MongoInstanceEvents.instanceReplState)).toEqual('STARTUP');
368+
expect(events.get(MongoInstanceEvents.instanceReplState)).toEqual('RECOVERING');
369369
expect(mongod.isInstancePrimary).toEqual(false);
370370
});
371371

0 commit comments

Comments
 (0)