@@ -151,17 +151,18 @@ describe('Retryable Reads Spec Prose', () => {
151151 requires : { mongodb : '>=4.4' , topology : 'replicaset' }
152152 } ;
153153
154- describe ( 'Retryable Reads Caused by Overload Errors Are Retried on a Different Server' , ( ) => {
154+ describe ( 'Retryable Reads Caused by Overload Errors Are Retried on a Different Server When enableOverloadRetargeting is enabled ' , ( ) => {
155155 let client : MongoClient ;
156156 const commandFailedEvents : CommandFailedEvent [ ] = [ ] ;
157157 const commandSucceededEvents : CommandSucceededEvent [ ] = [ ] ;
158158
159159 beforeEach ( async function ( ) {
160- // 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`, and command event monitoring
161- // enabled.
160+ // 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`,
161+ // `enableOverloadRetargeting=true`, and command event monitoring enabled.
162162 client = this . configuration . newClient ( {
163163 retryReads : true ,
164164 readPreference : 'primaryPreferred' ,
165+ enableOverloadRetargeting : true ,
165166 monitorCommands : true
166167 } ) ;
167168
@@ -278,5 +279,73 @@ describe('Retryable Reads Spec Prose', () => {
278279 expect ( commandFailedEvents [ 0 ] . address ) . to . equal ( commandSucceededEvents [ 0 ] . address ) ;
279280 } ) ;
280281 } ) ;
282+
283+ describe ( 'Retryable Reads Caused by Overload Errors Are Retried on Same Server When enableOverloadRetargeting is disabled' , ( ) => {
284+ let client : MongoClient ;
285+ const commandFailedEvents : CommandFailedEvent [ ] = [ ] ;
286+ const commandSucceededEvents : CommandSucceededEvent [ ] = [ ] ;
287+
288+ beforeEach ( async function ( ) {
289+ // 1. Create a client `client` with `retryReads=true`, `readPreference=primaryPreferred`, and command event monitoring
290+ // enabled.
291+ client = this . configuration . newClient ( {
292+ retryReads : true ,
293+ readPreference : 'primaryPreferred' ,
294+ monitorCommands : true
295+ } ) ;
296+
297+ client . on ( 'commandFailed' , filterForCommands ( 'find' , commandFailedEvents ) ) ;
298+ client . on ( 'commandSucceeded' , filterForCommands ( 'find' , commandSucceededEvents ) ) ;
299+
300+ await client . connect ( ) ;
301+
302+ /*
303+ * 2. Configure the following fail point for `client`:
304+ {
305+ configureFailPoint: "failCommand",
306+ mode: { times: 1 },
307+ data: {
308+ failCommands: ["find"],
309+ errorLabels: ["RetryableError", "SystemOverloadedError"]
310+ errorCode: 6
311+ }
312+ }
313+ * */
314+ await client . db ( 'admin' ) . command ( {
315+ configureFailPoint : 'failCommand' ,
316+ mode : { times : 1 } ,
317+ data : {
318+ failCommands : [ 'find' ] ,
319+ errorCode : 6 ,
320+ errorLabels : [ 'RetryableError' , 'SystemOverloadedError' ]
321+ }
322+ } ) ;
323+
324+ // 3. Reset the command event monitor to clear the failpoint command from its stored events.
325+ commandFailedEvents . length = 0 ;
326+ commandSucceededEvents . length = 0 ;
327+ } ) ;
328+
329+ afterEach ( async function ( ) {
330+ await client ?. db ( 'admin' ) . command ( { configureFailPoint : 'failCommand' , mode : 'off' } ) ;
331+ await client ?. close ( ) ;
332+ } ) ;
333+
334+ it (
335+ 'retries on the same server when SystemOverloadedError and enableOverloadRetargeting is disabled' ,
336+ TEST_METADATA ,
337+ async ( ) => {
338+ // 4. Execute a `find` command with `client`.
339+ await client . db ( 'test' ) . collection ( 'test' ) . find ( ) . toArray ( ) ;
340+
341+ // 5. Assert that one failed command event and one successful command event occurred.
342+ expect ( commandFailedEvents ) . to . have . lengthOf ( 1 ) ;
343+ expect ( commandSucceededEvents ) . to . have . lengthOf ( 1 ) ;
344+
345+ // 6. Assert that both events occurred on the same server.
346+ expect ( commandFailedEvents [ 0 ] . address ) . to . equal ( commandSucceededEvents [ 0 ] . address ) ;
347+ }
348+ ) ;
349+ } ) ;
281350 } ) ;
282351} ) ;
0 commit comments