Skip to content

Commit 41b1b32

Browse files
committed
fixup: update tests
1 parent d919fe9 commit 41b1b32

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

packages/mongodb-runner/src/mongocluster.spec.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,12 @@ describe('MongoCluster', function () {
289289
// This is the easiest way to ensure that MongoServer can handle the
290290
// pre-4.4 log format (because in the devtools-shared CI, we only
291291
// test ubuntu-latest).
292-
it('can spawn a 4.0.x replset using docker', async function () {
292+
it('can spawn a 4.2.x replset using docker', async function () {
293293
cluster = await MongoCluster.start({
294-
version: '4.0.x',
294+
version: '4.2.x',
295295
topology: 'replset',
296296
tmpDir,
297-
docker: 'mongo:4.0',
297+
docker: 'mongo:4.2',
298298
downloadOptions: {
299299
distro: 'ubuntu1604',
300300
},
@@ -307,12 +307,12 @@ describe('MongoCluster', function () {
307307
expect(+hello.passives.length + +hello.hosts.length).to.equal(3);
308308
});
309309

310-
it('can spawn a 4.0.x sharded env using docker', async function () {
310+
it('can spawn a 4.2.x sharded env using docker', async function () {
311311
cluster = await MongoCluster.start({
312-
version: '4.0.x',
312+
version: '4.2.x',
313313
topology: 'sharded',
314314
tmpDir,
315-
docker: 'mongo:4.0',
315+
docker: 'mongo:4.2',
316316
shards: 1,
317317
secondaries: 0,
318318
downloadOptions: {
@@ -327,9 +327,9 @@ describe('MongoCluster', function () {
327327
expect(hello.msg).to.equal('isdbgrid');
328328
});
329329

330-
it('can spawn a 4.0.x standalone mongod with TLS enabled and get build info', async function () {
330+
it('can spawn a 4.2.x standalone mongod with TLS enabled and get build info', async function () {
331331
cluster = await MongoCluster.start({
332-
version: '4.0.x',
332+
version: '4.2.x',
333333
topology: 'standalone',
334334
tmpDir,
335335
args: [
@@ -342,7 +342,7 @@ describe('MongoCluster', function () {
342342
],
343343
docker: [
344344
`--volume=${path.resolve(__dirname, '..')}:/projectroot:ro`,
345-
'mongo:4.0',
345+
'mongo:4.2',
346346
],
347347
downloadOptions: {
348348
distro: 'ubuntu1604',
@@ -580,11 +580,13 @@ describe('MongoCluster', function () {
580580
[50000, 'isdbgrid', false],
581581
]);
582582

583-
const mongosList = await cluster.withClient(
584-
async (client) =>
585-
await client.db('config').collection('mongos').find().toArray(),
586-
);
587-
expect(mongosList).to.have.lengthOf(2);
583+
await eventually(async () => {
584+
const mongosList = await cluster.withClient(
585+
async (client) =>
586+
await client.db('config').collection('mongos').find().toArray(),
587+
);
588+
expect(mongosList).to.have.lengthOf(2);
589+
});
588590
});
589591

590592
it('can add authentication options and verify them after serialization', async function () {

packages/mongodb-runner/src/util.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,25 @@ export function makeConnectionString(
9393
}
9494
return cs.toString();
9595
}
96+
97+
export async function eventually(
98+
fn: () => Promise<void> | void,
99+
{
100+
intervalMs = 100,
101+
timeoutMs = 5000,
102+
}: { intervalMs?: number; timeoutMs?: number } = {},
103+
): Promise<void> {
104+
const startTime = Date.now();
105+
// eslint-disable-next-line no-constant-condition
106+
while (true) {
107+
try {
108+
await fn();
109+
} catch (err) {
110+
if (Date.now() - startTime > timeoutMs) {
111+
throw err;
112+
} else {
113+
await sleep(intervalMs);
114+
}
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)