Skip to content

Commit d29c2db

Browse files
committed
test(replset-single): test that "_waitForPrimary" throws an error if timeout is reached
1 parent 89c8af6 commit d29c2db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,16 @@ describe('MongoMemoryReplSet', () => {
323323
expect(await replSet.stop()).toEqual(false);
324324
expect(instance.stop).toBeCalledTimes(1);
325325
});
326+
327+
it('"_waitForPrimary" should throw an error if timeout is reached', async () => {
328+
const replSet = new MongoMemoryReplSet();
329+
330+
try {
331+
// @ts-expect-error
332+
await replSet._waitForPrimary(1); // 1ms to be fast (0 and 1 are equal for "setTimeout" in js)
333+
fail('Expected "_waitForPrimary" to throw');
334+
} catch (err) {
335+
expect(err.message).toEqual('Timed out after 1ms while waiting for an Primary');
336+
}
337+
});
326338
});

0 commit comments

Comments
 (0)