Skip to content

Commit ab8a401

Browse files
fix failing tests
1 parent 1c03845 commit ab8a401

File tree

1 file changed

+99
-79
lines changed

1 file changed

+99
-79
lines changed

test/integration/crud/explain.test.ts

Lines changed: 99 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -362,35 +362,43 @@ describe('CRUD API explain option', function () {
362362
}
363363
);
364364

365-
test('the explain command has the calculated maxTimeMS value attached', async function () {
366-
const cursor = client.db('foo').collection('bar').find({}, { timeoutMS: 1000 });
367-
const timeout = await cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e);
368-
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
369-
370-
const [
371-
{
372-
command: { maxTimeMS }
373-
}
374-
] = commands;
375-
376-
expect(maxTimeMS).to.be.a('number');
377-
});
365+
it(
366+
'the explain command has the calculated maxTimeMS value attached',
367+
{ requires: { mongodb: '>=4.4' } },
368+
async function () {
369+
const cursor = client.db('foo').collection('bar').find({}, { timeoutMS: 1000 });
370+
const timeout = await cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e);
371+
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
372+
373+
const [
374+
{
375+
command: { maxTimeMS }
376+
}
377+
] = commands;
378378

379-
test('the explained command does not have a maxTimeMS value attached', async function () {
380-
const cursor = client.db('foo').collection('bar').find({}, { timeoutMS: 1000 });
381-
const timeout = await cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e);
382-
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
379+
expect(maxTimeMS).to.be.a('number');
380+
}
381+
);
383382

384-
const [
385-
{
386-
command: {
387-
explain: { maxTimeMS }
383+
it(
384+
'the explained command does not have a maxTimeMS value attached',
385+
{ requires: { mongodb: '>=4.4' } },
386+
async function () {
387+
const cursor = client.db('foo').collection('bar').find({}, { timeoutMS: 1000 });
388+
const timeout = await cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e);
389+
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
390+
391+
const [
392+
{
393+
command: {
394+
explain: { maxTimeMS }
395+
}
388396
}
389-
}
390-
] = commands;
397+
] = commands;
391398

392-
expect(maxTimeMS).not.to.exist;
393-
});
399+
expect(maxTimeMS).not.to.exist;
400+
}
401+
);
394402
});
395403

396404
describe('when timeoutMS and maxTimeMS are both provided', function () {
@@ -433,73 +441,85 @@ describe('CRUD API explain option', function () {
433441
}
434442
);
435443

436-
test('the explain command has the calculated maxTimeMS value attached', async function () {
437-
const timeout = await client
438-
.db('foo')
439-
.collection('bar')
440-
.deleteMany(
441-
{},
444+
it(
445+
'the explain command has the calculated maxTimeMS value attached',
446+
{ requires: { mongodb: '>=4.4' } },
447+
async function () {
448+
const timeout = await client
449+
.db('foo')
450+
.collection('bar')
451+
.deleteMany(
452+
{},
453+
{
454+
timeoutMS: 1000,
455+
explain: { verbosity: 'queryPlanner' }
456+
}
457+
)
458+
.catch(e => e);
459+
460+
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
461+
462+
const [
442463
{
443-
timeoutMS: 1000,
444-
explain: { verbosity: 'queryPlanner' }
464+
command: { maxTimeMS }
445465
}
446-
)
447-
.catch(e => e);
466+
] = commands;
448467

449-
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
468+
expect(maxTimeMS).to.be.a('number');
469+
}
470+
);
450471

451-
const [
452-
{
453-
command: { maxTimeMS }
454-
}
455-
] = commands;
472+
it(
473+
'the explained command does not have a maxTimeMS value attached',
474+
{ requires: { mongodb: '>=4.4' } },
475+
async function () {
476+
const timeout = await client
477+
.db('foo')
478+
.collection('bar')
479+
.deleteMany(
480+
{},
481+
{
482+
timeoutMS: 1000,
483+
explain: { verbosity: 'queryPlanner' }
484+
}
485+
)
486+
.catch(e => e);
456487

457-
expect(maxTimeMS).to.be.a('number');
458-
});
488+
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
459489

460-
test('the explained command does not have a maxTimeMS value attached', async function () {
461-
const timeout = await client
462-
.db('foo')
463-
.collection('bar')
464-
.deleteMany(
465-
{},
490+
const [
466491
{
467-
timeoutMS: 1000,
468-
explain: { verbosity: 'queryPlanner' }
469-
}
470-
)
471-
.catch(e => e);
472-
473-
expect(timeout).to.be.instanceOf(MongoOperationTimeoutError);
474-
475-
const [
476-
{
477-
command: {
478-
explain: { maxTimeMS }
492+
command: {
493+
explain: { maxTimeMS }
494+
}
479495
}
480-
}
481-
] = commands;
496+
] = commands;
482497

483-
expect(maxTimeMS).not.to.exist;
484-
});
498+
expect(maxTimeMS).not.to.exist;
499+
}
500+
);
485501
});
486502

487503
describe('when timeoutMS and maxTimeMS are both provided', function () {
488-
test('an error is thrown indicating incompatibility of those options', async function () {
489-
const error = await client
490-
.db('foo')
491-
.collection('bar')
492-
.deleteMany(
493-
{},
494-
{
495-
timeoutMS: 1000,
496-
explain: { verbosity: 'queryPlanner', maxTimeMS: 1000 }
497-
}
498-
)
499-
.catch(e => e);
504+
it(
505+
'an error is thrown indicating incompatibility of those options',
506+
{ requires: { mongodb: '>=4.4' } },
507+
async function () {
508+
const error = await client
509+
.db('foo')
510+
.collection('bar')
511+
.deleteMany(
512+
{},
513+
{
514+
timeoutMS: 1000,
515+
explain: { verbosity: 'queryPlanner', maxTimeMS: 1000 }
516+
}
517+
)
518+
.catch(e => e);
500519

501-
expect(error).to.match(/Cannot use maxTimeMS with timeoutMS for explain commands/);
502-
});
520+
expect(error).to.match(/Cannot use maxTimeMS with timeoutMS for explain commands/);
521+
}
522+
);
503523
});
504524
});
505525

0 commit comments

Comments
 (0)