Skip to content

Commit a6156bc

Browse files
W-A-Jamesnbbeeken
authored andcommitted
fix unit tests
1 parent 3a41fac commit a6156bc

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

test/unit/assorted/server_discovery_and_monitoring.spec.test.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ async function executeSDAMTest(testData: SDAMTest) {
334334
// phase with applicationErrors simulating error's from network, timeouts, server
335335
for (const appError of phase.applicationErrors) {
336336
// 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));
340340

341341
const server = client.topology.s.servers.get(appError.address);
342342

@@ -345,7 +345,7 @@ async function executeSDAMTest(testData: SDAMTest) {
345345
const thrownError = await res.catch(error => error);
346346

347347
// Restore the stub before asserting anything in case of errors
348-
withConnectionStub.restore();
348+
checkOutStub.restore();
349349

350350
const isApplicationError = error => {
351351
// These errors all come from the withConnection stub
@@ -404,15 +404,13 @@ async function executeSDAMTest(testData: SDAMTest) {
404404
}
405405
}
406406

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;
411410
const fakeConnection = {
412411
generation:
413412
typeof appError.generation === 'number' ? appError.generation : connectionPool.generation,
414-
415-
async command(_ns, _cmd, _options) {
413+
async command(_, __, ___) {
416414
if (appError.type === 'network') {
417415
throw new MongoNetworkError('test generated');
418416
} else if (appError.type === 'timeout') {
@@ -424,16 +422,7 @@ function withConnectionStubImpl(appError) {
424422
}
425423
}
426424
};
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;
437426
};
438427
}
439428

0 commit comments

Comments
 (0)