Skip to content

test(NODE-7534): add prose tests for retry behavior with mixed overload/non-overload errors#4921

Open
nbbeeken wants to merge 4 commits intomainfrom
NODE-7534
Open

test(NODE-7534): add prose tests for retry behavior with mixed overload/non-overload errors#4921
nbbeeken wants to merge 4 commits intomainfrom
NODE-7534

Conversation

@nbbeeken
Copy link
Copy Markdown
Contributor

Description

Summary of Changes

  • Add 4 new prose tests per spec commit 7039e69
  • Test 4 (reads/writes): Verify MAX_RETRIES applies to all errors after overload
  • Test 5 (reads/writes): Verify backoff only applies to overload errors
  • Uses mocking pattern consistent with existing prose tests
Notes for Reviewers

WIP

What is the motivation for this change?

Coverage reccomended by spec

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

…-overload errors

- Add 4 new prose tests per spec commit 7039e69
- Test 4 (reads/writes): Verify MAX_RETRIES applies to all errors after overload
- Test 5 (reads/writes): Verify backoff only applies to overload errors
- Uses mocking pattern consistent with existing prose tests
@nbbeeken nbbeeken marked this pull request as ready for review April 16, 2026 17:15
@nbbeeken nbbeeken requested a review from a team as a code owner April 16, 2026 17:15
Copilot AI review requested due to automatic review settings April 16, 2026 17:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new prose integration tests to validate the driver’s retry behavior when encountering an initial SystemOverloadedError followed by subsequent non-overload retryable errors, per the referenced spec guidance.

Changes:

  • Add new retryable-writes prose cases to verify MAX_RETRIES is honored across mixed overload/non-overload retryable write errors.
  • Add new retryable-reads prose cases to verify MAX_RETRIES is honored across mixed overload/non-overload retryable read errors.
  • Add timing-based assertions (via measureDuration) to ensure backoff is only applied to overload-labeled errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/integration/retryable-writes/retryable_writes.spec.prose.test.ts Adds Case 4/5 prose tests for mixed overload/non-overload retry behavior and backoff timing for retryable writes.
test/integration/retryable-reads/retryable_reads.spec.prose.test.ts Adds new prose suites to validate max-retry behavior and backoff timing for retryable reads under mixed error-label sequences.

Comment thread test/integration/retryable-reads/retryable_reads.spec.prose.test.ts Outdated
Comment thread test/integration/retryable-reads/retryable_reads.spec.prose.test.ts Outdated
Comment thread test/integration/retryable-reads/retryable_reads.spec.prose.test.ts
@tadjik1 tadjik1 self-assigned this Apr 20, 2026
@tadjik1 tadjik1 added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 20, 2026
@tadjik1 tadjik1 added the Team Review Needs review from team label Apr 21, 2026
@tadjik1 tadjik1 removed their assignment Apr 21, 2026
@tadjik1 tadjik1 removed Primary Review In Review with primary reviewer, not yet ready for team's eyes Team Review Needs review from team labels Apr 21, 2026
@PavelSafronov PavelSafronov self-assigned this Apr 21, 2026
@PavelSafronov PavelSafronov added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 21, 2026
TEST_METADATA,
async function () {
// Configure the random number generator used for jitter to always return a number as close as possible to `1`.
const randomStub = sinon.stub(Math, 'random');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing this so we can have a predictable wait. The spec requires this:

Assert that backoff was applied only once for the initial overload error and not for the subsequent
non-overload retryable errors.

Should the spec be updated with instructions to use this approach? Or is it largely up to each team to determine how this gets verified?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new prose tests to validate retry/backoff behavior when an initial SystemOverloadedError is followed by retryable non-overload errors, aligning with the retryable reads/writes prose spec scenarios.

Changes:

  • Add “Case 4” tests asserting MAX_RETRIES + 1 attempts occur even when later retryable errors are not overload errors (reads + writes).
  • Add “Case 5” tests intended to assert backoff is applied only for overload errors (reads + writes).
  • Introduce measureDuration usage to time retry sequences for the backoff assertions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/integration/retryable-writes/retryable_writes.spec.prose.test.ts Adds two new prose cases (max retries after overload; backoff only for overload) using Server.prototype.command stubbing + timing.
test/integration/retryable-reads/retryable_reads.spec.prose.test.ts Adds two new prose describes for the same behaviors for reads, including new imports and per-describe client lifecycle hooks.

Comment on lines +689 to +691
// If the driver incorrectly applied backoff to all retries, total would be 0.99*(100+200) = ~297ms.
const expectedMinBackoff = 90; // First backoff
const expectedMaxBackoff = expectedMinBackoff + 1000; // Allow 1 second margin for test overhead
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment seems reasonable. @nbbeeken , can we use Math.random=0 to test the very shortest time it should take to run all the operations?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes seems reasonable

Comment on lines +506 to +507
const expectedMinBackoff = 90; // First backoff
const expectedMaxBackoff = expectedMinBackoff + 1000; // Allow 1 second margin for test overhead
Comment on lines +365 to +379
let client: MongoClient;

beforeEach(async function () {
// 1. Create a client.
client = this.configuration.newClient({
monitorCommands: true,
retryReads: true
});
await client.connect();
});

afterEach(async function () {
sinon.restore();
await client?.close();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line 365?

@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Apr 22, 2026
Copy link
Copy Markdown
Contributor Author

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants