Skip to content

Commit c69eb98

Browse files
Add tests for retry loop and backoff.
1 parent 91abffd commit c69eb98

File tree

10 files changed

+7524
-8
lines changed

10 files changed

+7524
-8
lines changed

src/operations/execute_operation.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
} from '../utils';
3939
import { AggregateOperation } from './aggregate';
4040
import { AbstractOperation, Aspect } from './operation';
41+
import { RunCommandOperation } from './run_command';
4142

4243
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
4344
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
@@ -264,16 +265,16 @@ async function executeOperationWithRetries<
264265
if (previousOperationError.hasErrorLabel(MongoErrorLabel.SystemOverloadedError)) {
265266
systemOverloadRetryAttempt += 1;
266267

268+
// if retryable writes or reads are not configured, throw.
269+
const isOperationConfiguredForRetry =
270+
(hasReadAspect && topology.s.options.retryReads) ||
271+
(hasWriteAspect && topology.s.options.retryWrites);
272+
const isRunCommand = operation instanceof RunCommandOperation;
273+
267274
if (
268275
// if the SystemOverloadError is not retryable, throw.
269276
!previousOperationError.hasErrorLabel(MongoErrorLabel.RetryableError) ||
270-
!(
271-
// if retryable writes or reads are not configured, throw.
272-
(
273-
(hasReadAspect && topology.s.options.retryReads) ||
274-
(hasWriteAspect && topology.s.options.retryWrites)
275-
)
276-
)
277+
!(isOperationConfiguredForRetry || isRunCommand)
277278
) {
278279
throw previousOperationError;
279280
}
@@ -360,7 +361,10 @@ async function executeOperationWithRetries<
360361

361362
try {
362363
// If attempt > 0 and we are command batching we need to reset the batch.
363-
if (nonOverloadRetryAttempt > 0 && operation.hasAspect(Aspect.COMMAND_BATCHING)) {
364+
if (
365+
(nonOverloadRetryAttempt > 0 || systemOverloadRetryAttempt > 0) &&
366+
operation.hasAspect(Aspect.COMMAND_BATCHING)
367+
) {
364368
operation.resetBatch();
365369
}
366370

sync.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
cp ~/dev/specifications/source/client-backpressure/tests/* ~/dev/node-mongodb-native/test/spec/client-backpressure
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { loadSpecTests } from '../../spec';
2+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
3+
import { type Test } from '../../tools/unified-spec-runner/schema';
4+
5+
const skippedTests = {
6+
'collection.dropIndexes retries at most maxAttempts times (maxAttempts=5)':
7+
'TODO(NODE-6517): dropIndexes squashes all errors other than ns not found'
8+
};
9+
10+
function shouldSkip({ description }: Test) {
11+
return skippedTests[description] ?? false;
12+
}
13+
14+
describe('Client Backpressure (spec)', function () {
15+
runUnifiedSuite(loadSpecTests('client-backpressure'), shouldSkip);
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Client Backpressure Tests
2+
3+
______________________________________________________________________
4+
5+
## Introduction
6+
7+
The YAML and JSON files in this directory are platform-independent tests meant to exercise a driver's implementation of
8+
retryable reads. These tests utilize the [Unified Test Format](../../unified-test-format/unified-test-format.md).
9+
10+
Several prose tests, which are not easily expressed in YAML, are also presented in this file. Those tests will need to
11+
be manually implemented by each driver.
12+
13+
## Changelog
14+
15+
- 2025-XX-XX: Initial version.

0 commit comments

Comments
 (0)