Skip to content

Commit edc73b0

Browse files
fix tests?
1 parent e08206a commit edc73b0

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
lines changed

test/integration/crud/explain.test.ts

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,28 +317,30 @@ describe('CRUD API explain option', function () {
317317
}
318318

319319
beforeEach(async function () {
320-
client = this.configuration.newClient(
321-
{},
322-
{ monitorCommands: true, minPoolSize: 5, appName: 'explain-tests' }
323-
);
320+
const uri = this.configuration.url({ useMultipleMongoses: false });
321+
client = this.configuration.newClient(uri, { monitorCommands: true });
324322
client.on('commandStarted', filterForCommands('explain', commands));
325323

326-
waitUntilPoolsFilled(client, AbortSignal.timeout(30_000), 4);
327-
328-
await configureFailPoint(this.configuration, {
329-
configureFailPoint: 'failCommand',
330-
mode: { times: 1 },
331-
data: {
332-
failCommands: ['explain'],
333-
blockConnection: true,
334-
blockTimeMS: 1000,
335-
appName: 'explain-tests'
336-
}
337-
});
324+
await configureFailPoint(
325+
this.configuration,
326+
{
327+
configureFailPoint: 'failCommand',
328+
mode: { times: 1 },
329+
data: {
330+
failCommands: ['explain'],
331+
blockConnection: true,
332+
blockTimeMS: 1000
333+
}
334+
},
335+
uri
336+
);
338337
});
339338

340339
afterEach(async function () {
341-
await clearFailPoint(this.configuration);
340+
await clearFailPoint(
341+
this.configuration,
342+
this.configuration.url({ useMultipleMongoses: false })
343+
);
342344
await client?.close();
343345
commands.length = 0;
344346
});
@@ -535,6 +537,12 @@ describe('CRUD API explain option', function () {
535537
const { result, duration } = await measureDuration(() =>
536538
cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e)
537539
);
540+
const [
541+
{
542+
command: { maxTimeMS }
543+
}
544+
] = commands;
545+
expect(maxTimeMS).to.exist;
538546
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
539547
expect(duration).to.be.within(1000 - 100, 1000 + 100);
540548
});
@@ -547,6 +555,12 @@ describe('CRUD API explain option', function () {
547555
const { result, duration } = await measureDuration(() =>
548556
cursor.explain({ verbosity: 'queryPlanner' }, { timeoutMS: 1000 }).catch(e => e)
549557
);
558+
const [
559+
{
560+
command: { maxTimeMS }
561+
}
562+
] = commands;
563+
expect(maxTimeMS).to.exist;
550564
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
551565
expect(duration).to.be.within(1000 - 100, 1000 + 100);
552566
});
@@ -558,6 +572,12 @@ describe('CRUD API explain option', function () {
558572
const { result, duration } = await measureDuration(() =>
559573
cursor.explain({ verbosity: 'queryPlanner' }, { timeoutMS: 1000 }).catch(e => e)
560574
);
575+
const [
576+
{
577+
command: { maxTimeMS }
578+
}
579+
] = commands;
580+
expect(maxTimeMS).to.exist;
561581
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
562582
expect(duration).to.be.within(1000 - 100, 1000 + 100);
563583
});
@@ -570,6 +590,12 @@ describe('CRUD API explain option', function () {
570590
cursor.explain({ verbosity: 'queryPlanner' }).catch(e => e)
571591
);
572592

593+
const [
594+
{
595+
command: { maxTimeMS }
596+
}
597+
] = commands;
598+
expect(maxTimeMS).to.exist;
573599
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
574600
expect(duration).to.be.within(1000 - 100, 1000 + 100);
575601
});
@@ -581,7 +607,12 @@ describe('CRUD API explain option', function () {
581607
const { result, duration } = await measureDuration(() =>
582608
cursor.explain({ verbosity: 'queryPlanner' }, { timeoutMS: 1000 }).catch(e => e)
583609
);
584-
610+
const [
611+
{
612+
command: { maxTimeMS }
613+
}
614+
] = commands;
615+
expect(maxTimeMS).to.exist;
585616
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
586617
expect(duration).to.be.within(1000 - 100, 1000 + 100);
587618
});
@@ -593,6 +624,12 @@ describe('CRUD API explain option', function () {
593624
const { duration, result } = await measureDuration(() =>
594625
cursor.explain({ verbosity: 'queryPlanner' }, { timeoutMS: 1000 }).catch(e => e)
595626
);
627+
const [
628+
{
629+
command: { maxTimeMS }
630+
}
631+
] = commands;
632+
expect(maxTimeMS).to.exist;
596633
expect(duration).to.be.within(1000 - 100, 1000 + 100);
597634
expect(result).to.be.instanceOf(MongoOperationTimeoutError);
598635
});

test/tools/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,12 @@ export async function waitUntilPoolsFilled(
601601
await Promise.all([wait$(), client.connect()]);
602602
}
603603

604-
export async function configureFailPoint(configuration: TestConfiguration, failPoint: FailPoint) {
605-
const utilClient = configuration.newClient();
604+
export async function configureFailPoint(
605+
configuration: TestConfiguration,
606+
failPoint: FailPoint,
607+
uri = configuration.url()
608+
) {
609+
const utilClient = configuration.newClient(uri);
606610
await utilClient.connect();
607611

608612
try {
@@ -612,8 +616,8 @@ export async function configureFailPoint(configuration: TestConfiguration, failP
612616
}
613617
}
614618

615-
export async function clearFailPoint(configuration: TestConfiguration) {
616-
const utilClient = configuration.newClient();
619+
export async function clearFailPoint(configuration: TestConfiguration, url = configuration.url()) {
620+
const utilClient = configuration.newClient(url);
617621
await utilClient.connect();
618622

619623
try {

0 commit comments

Comments
 (0)