Skip to content

Commit

Permalink
test: retry starting mongo memory server to get around port issues
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Aug 3, 2024
1 parent 45f8d2f commit 677ff1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/features/partial-loading/GH5889.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ beforeAll(async () => {

afterAll(() => orm.close(true));

test('foo', async () => {
test('5889', async () => {
await createEntities();

const mock = mockLogger(orm);
Expand Down
27 changes: 21 additions & 6 deletions tests/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { MongoMemoryReplSet } from 'mongodb-memory-server-core';

export = async function globalSetup() {
const instance = await MongoMemoryReplSet.create({
replSet: {
name: 'rs',
count: 3,
},
});
let instance;
let error;

for (let i = 0; i < 5; i++) {
try {
instance = await MongoMemoryReplSet.create({
replSet: {
name: 'rs',
count: 3,
},
});
break;
} catch (err) {
error = err;
}
}

if (!instance) {
throw new Error('Cannot start mongodb memory server', { cause: error });
}

await instance.waitUntilRunning();
const uri = instance.getUri();
(global as any).__MONGOINSTANCE = instance;
Expand Down

0 comments on commit 677ff1b

Please sign in to comment.