Skip to content

Commit 475f9a6

Browse files
committed
update tests
1 parent 7db354a commit 475f9a6

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type Collection,
77
type CommandFailedEvent,
88
type CommandSucceededEvent,
9-
MAX_RETRIES,
109
type MongoClient,
1110
MongoErrorLabel,
1211
MongoServerError,
@@ -368,7 +367,8 @@ describe('Retryable Reads Spec Prose', () => {
368367
beforeEach(async function () {
369368
// 1. Create a client.
370369
client = this.configuration.newClient({
371-
monitorCommands: true
370+
monitorCommands: true,
371+
retryReads: true
372372
});
373373
await client.connect();
374374
});
@@ -415,8 +415,11 @@ describe('Retryable Reads Spec Prose', () => {
415415
.findOne({})
416416
.catch(e => e);
417417

418-
expect(error).to.exist;
419-
expect(serverCommandStub.callCount).to.equal(MAX_RETRIES + 1);
418+
expect(error).to.be.instanceOf(MongoServerError);
419+
expect(error.code).to.equal(91);
420+
expect(error.hasErrorLabel(MongoErrorLabel.RetryableError)).to.be.true;
421+
// MAX_RETRIES + 1 (default maxAdaptiveRetries is 2).
422+
expect(serverCommandStub.callCount).to.equal(3);
420423
}
421424
);
422425
});
@@ -434,7 +437,8 @@ describe('Retryable Reads Spec Prose', () => {
434437
beforeEach(async function () {
435438
// 1. Create a client.
436439
client = this.configuration.newClient({
437-
monitorCommands: true
440+
monitorCommands: true,
441+
retryReads: true
438442
});
439443
await client.connect();
440444
});
@@ -486,9 +490,15 @@ describe('Retryable Reads Spec Prose', () => {
486490
.collection('test')
487491
.findOne({})
488492
.catch(e => e);
489-
expect(error).to.exist;
493+
expect(error).to.be.instanceOf(MongoServerError);
494+
expect(error.code).to.equal(91);
490495
});
491496

497+
// Ensure the full retry sequence executed (i.e. the test really exercised the
498+
// post-overload non-overload retries, not just bailed after the first attempt).
499+
// MAX_RETRIES + 1 (default maxAdaptiveRetries is 2).
500+
expect(serverCommandStub.callCount).to.equal(3);
501+
492502
// The expected backoff for the first (overload) error is: Math.random() * Math.min(10000, 100 * 2^0)
493503
// With Math.random() = 0.99, this gives us: 0.99 * 100 = 99ms
494504
// Subsequent errors are non-overload, so they should have NO backoff applied.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as sinon from 'sinon';
66

77
import {
88
type Collection,
9-
MAX_RETRIES,
109
type MongoClient,
1110
MongoError,
1211
MongoErrorLabel,
@@ -609,7 +608,10 @@ describe('Retryable Writes Spec Prose', () => {
609608
const insertResult = await collection.insertOne({ _id: 1 }).catch(error => error);
610609

611610
expect(insertResult).to.be.instanceOf(MongoServerError);
612-
expect(serverCommandStub.callCount).to.equal(MAX_RETRIES + 1);
611+
expect(insertResult.code).to.equal(91);
612+
expect(insertResult.hasErrorLabel(MongoErrorLabel.RetryableError)).to.be.true;
613+
// MAX_RETRIES + 1 (default maxAdaptiveRetries is 2).
614+
expect(serverCommandStub.callCount).to.equal(3);
613615
}
614616
);
615617

@@ -673,8 +675,14 @@ describe('Retryable Writes Spec Prose', () => {
673675
const { duration } = await measureDuration(async () => {
674676
const insertResult = await collection.insertOne({ _id: 1 }).catch(error => error);
675677
expect(insertResult).to.be.instanceOf(MongoServerError);
678+
expect(insertResult.code).to.equal(91);
676679
});
677680

681+
// Ensure the full retry sequence executed (i.e. the test really exercised the
682+
// post-overload non-overload retries, not just bailed after the first attempt).
683+
// MAX_RETRIES + 1 (default maxAdaptiveRetries is 2).
684+
expect(serverCommandStub.callCount).to.equal(3);
685+
678686
// The expected backoff for the first (overload) error is: Math.random() * Math.min(10000, 100 * 2^0)
679687
// With Math.random() = 0.99, this gives us: 0.99 * 100 = 99ms
680688
// Subsequent errors are non-overload, so they should have NO backoff applied.

0 commit comments

Comments
 (0)