Skip to content

Commit 25192e1

Browse files
thresholds
1 parent 450b163 commit 25192e1

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

test/integration/client-side-operations-timeout/client_side_operations_timeout.prose.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
promiseWithResolvers,
2222
squashError
2323
} from '../../mongodb';
24-
import { type FailPoint, makeMultiBatchWrite } from '../../tools/utils';
24+
import { type FailPoint, makeMultiBatchWrite, waitUntilPoolsFilled } from '../../tools/utils';
2525
import { filterForCommands } from '../shared';
2626

2727
// TODO(NODE-5824): Implement CSOT prose tests
@@ -343,7 +343,7 @@ describe('CSOT spec prose tests', function () {
343343

344344
client = this.configuration.newClient(undefined, {
345345
monitorCommands: true,
346-
timeoutMS: 100,
346+
timeoutMS: 150,
347347
minPoolSize: 20
348348
});
349349
await client.connect();

test/integration/crud/client_bulk_write.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ describe('Client Bulk Write', function () {
320320

321321
it(
322322
'timeoutMS is refreshed to the timeoutMS passed to the bulk write for the killCursors command',
323-
metadata,
323+
{
324+
requires: { ...metadata.requires, topology: '!load-balanced' }
325+
},
324326
async function () {
325327
const models = await makeMultiResponseBatchModelArray(this.configuration);
326328
const timeoutError = await client

test/integration/node-specific/abstract_cursor.test.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { inspect } from 'util';
77
import {
88
AbstractCursor,
99
type Collection,
10+
type CommandStartedEvent,
1011
CursorTimeoutContext,
1112
CursorTimeoutMode,
1213
type FindCursor,
@@ -17,7 +18,8 @@ import {
1718
MongoServerError,
1819
TimeoutContext
1920
} from '../../mongodb';
20-
import { type FailPoint } from '../../tools/utils';
21+
import { clearFailPoint, configureFailPoint } from '../../tools/utils';
22+
import { filterForCommands } from '../shared';
2123

2224
describe('class AbstractCursor', function () {
2325
describe('regression tests NODE-5372', function () {
@@ -405,9 +407,11 @@ describe('class AbstractCursor', function () {
405407
let client: MongoClient;
406408
let collection: Collection;
407409
let context: CursorTimeoutContext;
410+
const commands: CommandStartedEvent[] = [];
408411

409412
beforeEach(async function () {
410-
client = this.configuration.newClient();
413+
client = this.configuration.newClient({}, { monitorCommands: true });
414+
client.on('commandStarted', filterForCommands('killCursors', commands));
411415

412416
collection = client.db('abstract_cursor_integration').collection('test');
413417

@@ -472,30 +476,48 @@ describe('class AbstractCursor', function () {
472476
});
473477
});
474478

475-
describe('when the cursor refreshes the timeout for killCursors', function () {
476-
it(
477-
'the provided timeoutContext is not modified',
478-
{
479-
requires: {
480-
mongodb: '>=4.4'
481-
}
482-
},
483-
async function () {
484-
await client.db('admin').command({
479+
describe('when the cursor refreshes the timeout for killCursors' + i, function () {
480+
let uri: string;
481+
482+
before(function () {
483+
uri = this.configuration.url({ useMultipleMongoses: false });
484+
});
485+
486+
beforeEach(async function () {
487+
commands.length = 0;
488+
await configureFailPoint(
489+
this.configuration,
490+
{
485491
configureFailPoint: 'failCommand',
486492
mode: { times: 1 },
487493
data: {
488494
failCommands: ['getMore'],
489495
blockConnection: true,
490496
blockTimeMS: 5000
491497
}
492-
} as FailPoint);
498+
},
499+
uri
500+
);
501+
});
493502

503+
afterEach(async function () {
504+
await clearFailPoint(this.configuration, uri);
505+
});
506+
507+
it(
508+
'the provided timeoutContext is not modified' + i,
509+
{
510+
requires: {
511+
mongodb: '>=4.4',
512+
topology: '!load-balanced'
513+
}
514+
},
515+
async function () {
494516
const cursor = collection.find(
495517
{},
496518
{
497519
timeoutContext: context,
498-
timeoutMS: 1000,
520+
timeoutMS: 150,
499521
timeoutMode: CursorTimeoutMode.LIFETIME,
500522
batchSize: 1
501523
}
@@ -504,7 +526,6 @@ describe('class AbstractCursor', function () {
504526
const error = await cursor.toArray().catch(e => e);
505527

506528
expect(error).to.be.instanceof(MongoOperationTimeoutError);
507-
// @ts-expect-error We know we have a CSOT timeout context but TS does not.
508529
expect(context.timeoutContext.remainingTimeMS).to.be.lessThan(0);
509530
}
510531
);

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, uri = configuration.url()) {
620+
const utilClient = configuration.newClient(uri);
617621
await utilClient.connect();
618622

619623
try {

0 commit comments

Comments
 (0)