Skip to content

Commit b0d0fb6

Browse files
committed
test(MongoMemoryReplSet): add test for "launchTimeout" to be set correctly
re #716
1 parent 499f20e commit b0d0fb6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import MongoMemoryReplSet, {
66
import { MongoClient, MongoServerError } from 'mongodb';
77
import MongoMemoryServer, { AutomaticAuth } from '../MongoMemoryServer';
88
import * as utils from '../util/utils';
9-
import { MongoMemoryInstanceOpts } from '../util/MongoInstance';
9+
import MongoInstance, { MongoMemoryInstanceOpts } from '../util/MongoInstance';
1010
import { ReplsetCountLowError, StateError, WaitForPrimaryTimeoutError } from '../util/errors';
1111
import { assertIsError } from './testUtils/test_utils';
1212
import * as debug from 'debug';
@@ -705,4 +705,23 @@ describe('MongoMemoryReplSet', () => {
705705

706706
await replSet.stop();
707707
});
708+
709+
it('should transfer "launchTimeout" option to the MongoInstance', async () => {
710+
jest.spyOn(MongoInstance.prototype, 'start').mockImplementation(
711+
// @ts-expect-error This can work, because the instance is not used in the function that is tested here, beyond setting some extra options
712+
() => Promise.resolve({})
713+
);
714+
715+
const replSet = new MongoMemoryReplSet({ instanceOpts: [{ launchTimeout: 2000 }] });
716+
717+
// @ts-expect-error "initAllServers" is protected
718+
await replSet.initAllServers();
719+
720+
// @ts-expect-error "_instanceInfo" is protected
721+
const instanceInfo = replSet.servers[0]._instanceInfo;
722+
expect(instanceInfo).toBeDefined();
723+
utils.assertion(!utils.isNullOrUndefined(instanceInfo));
724+
expect(instanceInfo.instance).toBeDefined();
725+
expect(instanceInfo?.launchTimeout).toStrictEqual(2000);
726+
});
708727
});

0 commit comments

Comments
 (0)