Skip to content

Commit 87431a1

Browse files
committed
update prose tests
1 parent 19cbb37 commit 87431a1

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

test/integration/client-backpressure/client-backpressure.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
33
import { type Test } from '../../tools/unified-spec-runner/schema';
44

55
const skippedTests = {
6-
'collection.dropIndexes retries at most maxAttempts=5 times':
6+
'collection.dropIndexes retries at most maxAttempts=2 times':
77
'TODO(NODE-6517): dropIndexes squashes all errors other than ns not found',
88
'collection.dropIndexes (write) does not retry if retryWrites=false':
99
'TODO(NODE-6517): dropIndexes squashes all errors other than ns not found'

test/integration/retryable-reads/retryable_reads.spec.prose.test.ts

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,18 @@ describe('Retryable Reads Spec Prose', () => {
151151
requires: { mongodb: '>=4.4', topology: 'replicaset' }
152152
};
153153

154-
describe('Retryable Reads Caused by Overload Errors Are Retried on a Different Server', () => {
154+
describe('Retryable Reads Caused by Overload Errors Are Retried on a Different Server When enableOverloadRetargeting is enabled', () => {
155155
let client: MongoClient;
156156
const commandFailedEvents: CommandFailedEvent[] = [];
157157
const commandSucceededEvents: CommandSucceededEvent[] = [];
158158

159159
beforeEach(async function () {
160-
// 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`, and command event monitoring
161-
// enabled.
160+
// 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`,
161+
// `enableOverloadRetargeting=true`, and command event monitoring enabled.
162162
client = this.configuration.newClient({
163163
retryReads: true,
164164
readPreference: 'primaryPreferred',
165+
enableOverloadRetargeting: true,
165166
monitorCommands: true
166167
});
167168

@@ -278,5 +279,73 @@ describe('Retryable Reads Spec Prose', () => {
278279
expect(commandFailedEvents[0].address).to.equal(commandSucceededEvents[0].address);
279280
});
280281
});
282+
283+
describe('Retryable Reads Caused by Overload Errors Are Retried on Same Server When enableOverloadRetargeting is disabled', () => {
284+
let client: MongoClient;
285+
const commandFailedEvents: CommandFailedEvent[] = [];
286+
const commandSucceededEvents: CommandSucceededEvent[] = [];
287+
288+
beforeEach(async function () {
289+
// 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`, and command event monitoring
290+
// enabled.
291+
client = this.configuration.newClient({
292+
retryReads: true,
293+
readPreference: 'primaryPreferred',
294+
monitorCommands: true
295+
});
296+
297+
client.on('commandFailed', filterForCommands('find', commandFailedEvents));
298+
client.on('commandSucceeded', filterForCommands('find', commandSucceededEvents));
299+
300+
await client.connect();
301+
302+
/*
303+
* 2. Configure the following fail point for `client`:
304+
{
305+
configureFailPoint: "failCommand",
306+
mode: { times: 1 },
307+
data: {
308+
failCommands: ["find"],
309+
errorLabels: ["RetryableError", "SystemOverloadedError"]
310+
errorCode: 6
311+
}
312+
}
313+
* */
314+
await client.db('admin').command({
315+
configureFailPoint: 'failCommand',
316+
mode: { times: 1 },
317+
data: {
318+
failCommands: ['find'],
319+
errorCode: 6,
320+
errorLabels: ['RetryableError', 'SystemOverloadedError']
321+
}
322+
});
323+
324+
// 3. Reset the command event monitor to clear the failpoint command from its stored events.
325+
commandFailedEvents.length = 0;
326+
commandSucceededEvents.length = 0;
327+
});
328+
329+
afterEach(async function () {
330+
await client?.db('admin').command({ configureFailPoint: 'failCommand', mode: 'off' });
331+
await client?.close();
332+
});
333+
334+
it(
335+
'retries on the same server when SystemOverloadedError and enableOverloadRetargeting is disabled',
336+
TEST_METADATA,
337+
async () => {
338+
// 4. Execute a `find` command with `client`.
339+
await client.db('test').collection('test').find().toArray();
340+
341+
// 5. Assert that one failed command event and one successful command event occurred.
342+
expect(commandFailedEvents).to.have.lengthOf(1);
343+
expect(commandSucceededEvents).to.have.lengthOf(1);
344+
345+
// 6. Assert that both events occurred on the same server.
346+
expect(commandFailedEvents[0].address).to.equal(commandSucceededEvents[0].address);
347+
}
348+
);
349+
});
281350
});
282351
});

test/integration/retryable-writes/retryable_writes.spec.prose.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ describe('Retryable Writes Spec Prose', () => {
479479
// server error. Assert that the error code of the server error is 91.
480480
const insertResult = await collection.insertOne({ _id: 1 }).catch(error => error);
481481

482-
expect(serverCommandStub.callCount).to.equal(6);
482+
// maxAdaptiveRetries defaults to 2, so we expect 3 total attempts (1 initial + 2 retries).
483+
expect(serverCommandStub.callCount).to.equal(3);
483484

484485
expect(insertResult).to.be.instanceOf(MongoServerError);
485486
expect(insertResult).to.have.property('code', 91);

0 commit comments

Comments
 (0)