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.
0 commit comments