Skip to content

Commit

Permalink
test(MongoMemoryReplSet): add test for "launchTimeout" to be set corr…
Browse files Browse the repository at this point in the history
…ectly

re #716
  • Loading branch information
hasezoey committed Jan 13, 2023
1 parent 499f20e commit b0d0fb6
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MongoMemoryReplSet, {
import { MongoClient, MongoServerError } from 'mongodb';
import MongoMemoryServer, { AutomaticAuth } from '../MongoMemoryServer';
import * as utils from '../util/utils';
import { MongoMemoryInstanceOpts } from '../util/MongoInstance';
import MongoInstance, { MongoMemoryInstanceOpts } from '../util/MongoInstance';
import { ReplsetCountLowError, StateError, WaitForPrimaryTimeoutError } from '../util/errors';
import { assertIsError } from './testUtils/test_utils';
import * as debug from 'debug';
Expand Down Expand Up @@ -705,4 +705,23 @@ describe('MongoMemoryReplSet', () => {

await replSet.stop();
});

it('should transfer "launchTimeout" option to the MongoInstance', async () => {
jest.spyOn(MongoInstance.prototype, 'start').mockImplementation(
// @ts-expect-error This can work, because the instance is not used in the function that is tested here, beyond setting some extra options
() => Promise.resolve({})
);

const replSet = new MongoMemoryReplSet({ instanceOpts: [{ launchTimeout: 2000 }] });

// @ts-expect-error "initAllServers" is protected
await replSet.initAllServers();

// @ts-expect-error "_instanceInfo" is protected
const instanceInfo = replSet.servers[0]._instanceInfo;
expect(instanceInfo).toBeDefined();
utils.assertion(!utils.isNullOrUndefined(instanceInfo));
expect(instanceInfo.instance).toBeDefined();
expect(instanceInfo?.launchTimeout).toStrictEqual(2000);
});
});

0 comments on commit b0d0fb6

Please sign in to comment.