Skip to content

Commit 8f07da6

Browse files
committed
round lower bound of the first retry
1 parent 475f9a6 commit 8f07da6

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,10 @@ describe('Retryable Reads Spec Prose', () => {
500500
expect(serverCommandStub.callCount).to.equal(3);
501501

502502
// The expected backoff for the first (overload) error is: Math.random() * Math.min(10000, 100 * 2^0)
503-
// With Math.random() = 0.99, this gives us: 0.99 * 100 = 99ms
504-
// Subsequent errors are non-overload, so they should have NO backoff applied.
505-
// We add a margin for test execution overhead.
506-
const expectedMinBackoff = 99; // First backoff
503+
// With Math.random() = 0.99, this gives ~99ms. `measureDuration` uses `Math.floor(performance.now())`
504+
// on both ends and setTimeout can fire a couple ms early, so we allow slack on the lower bound.
505+
// If the driver incorrectly applied backoff to all retries, total would be 0.99*(100+200) = ~297ms.
506+
const expectedMinBackoff = 90; // First backoff
507507
const expectedMaxBackoff = expectedMinBackoff + 1000; // Allow 1 second margin for test overhead
508508

509509
expect(duration).to.be.within(expectedMinBackoff, expectedMaxBackoff);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@ describe('Retryable Writes Spec Prose', () => {
684684
expect(serverCommandStub.callCount).to.equal(3);
685685

686686
// The expected backoff for the first (overload) error is: Math.random() * Math.min(10000, 100 * 2^0)
687-
// With Math.random() = 0.99, this gives us: 0.99 * 100 = 99ms
688-
// Subsequent errors are non-overload, so they should have NO backoff applied.
689-
// We add a margin for test execution overhead.
690-
const expectedMinBackoff = 99; // First backoff
687+
// With Math.random() = 0.99, this gives ~99ms. `measureDuration` uses `Math.floor(performance.now())`
688+
// on both ends and setTimeout can fire a couple ms early, so we allow slack on the lower bound.
689+
// If the driver incorrectly applied backoff to all retries, total would be 0.99*(100+200) = ~297ms.
690+
const expectedMinBackoff = 90; // First backoff
691691
const expectedMaxBackoff = expectedMinBackoff + 1000; // Allow 1 second margin for test overhead
692692

693693
expect(duration).to.be.within(expectedMinBackoff, expectedMaxBackoff);

0 commit comments

Comments
 (0)