@@ -334,9 +334,9 @@ async function executeSDAMTest(testData: SDAMTest) {
334
334
// phase with applicationErrors simulating error's from network, timeouts, server
335
335
for ( const appError of phase . applicationErrors ) {
336
336
// Stub will return appError to SDAM machinery
337
- const withConnectionStub = sinon
338
- . stub ( ConnectionPool . prototype , 'withConnection ' )
339
- . callsFake ( withConnectionStubImpl ( appError ) ) ;
337
+ const checkOutStub = sinon
338
+ . stub ( ConnectionPool . prototype , 'checkOut ' )
339
+ . callsFake ( checkoutStubImpl ( appError ) ) ;
340
340
341
341
const server = client . topology . s . servers . get ( appError . address ) ;
342
342
@@ -345,7 +345,7 @@ async function executeSDAMTest(testData: SDAMTest) {
345
345
const thrownError = await res . catch ( error => error ) ;
346
346
347
347
// Restore the stub before asserting anything in case of errors
348
- withConnectionStub . restore ( ) ;
348
+ checkOutStub . restore ( ) ;
349
349
350
350
const isApplicationError = error => {
351
351
// These errors all come from the withConnection stub
@@ -404,15 +404,13 @@ async function executeSDAMTest(testData: SDAMTest) {
404
404
}
405
405
}
406
406
407
- function withConnectionStubImpl ( appError ) {
408
- return function ( conn , fn , callback ) {
409
- // eslint-disable-next-line @typescript-eslint/no-this-alias
410
- const connectionPool = this ; // we are stubbing `withConnection` on the `ConnectionPool` class
407
+ function checkoutStubImpl ( appError ) {
408
+ return async function ( ) {
409
+ const connectionPool = this ;
411
410
const fakeConnection = {
412
411
generation :
413
412
typeof appError . generation === 'number' ? appError . generation : connectionPool . generation ,
414
-
415
- async command ( _ns , _cmd , _options ) {
413
+ async command ( _ , __ , ___ ) {
416
414
if ( appError . type === 'network' ) {
417
415
throw new MongoNetworkError ( 'test generated' ) ;
418
416
} else if ( appError . type === 'timeout' ) {
@@ -424,16 +422,7 @@ function withConnectionStubImpl(appError) {
424
422
}
425
423
}
426
424
} ;
427
-
428
- fn ( undefined , fakeConnection , ( fnErr , result ) => {
429
- if ( typeof callback === 'function' ) {
430
- if ( fnErr ) {
431
- callback ( fnErr ) ;
432
- } else {
433
- callback ( undefined , result ) ;
434
- }
435
- }
436
- } ) ;
425
+ return fakeConnection ;
437
426
} ;
438
427
}
439
428
0 commit comments