diff --git a/src/sessions.ts b/src/sessions.ts index 4c30bf5aea..d2e21e640d 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -413,14 +413,14 @@ export class ClientSession extends TypedEventEmitter { /** * Commits the currently active transaction in this session. */ - async commitTransaction(): Promise { + async commitTransaction(): Promise { return endTransactionAsync(this, 'commitTransaction'); } /** * Aborts the currently active transaction in this session. */ - async abortTransaction(): Promise { + async abortTransaction(): Promise { return endTransactionAsync(this, 'abortTransaction'); } @@ -636,14 +636,14 @@ const endTransactionAsync = promisify( endTransaction as ( session: ClientSession, commandName: 'abortTransaction' | 'commitTransaction', - callback: (error: Error, result: Document) => void + callback: (error: Error) => void ) => void ); function endTransaction( session: ClientSession, commandName: 'abortTransaction' | 'commitTransaction', - callback: Callback + callback: Callback ) { // handle any initial problematic cases const txnState = session.transaction.state; @@ -717,7 +717,7 @@ function endTransaction( Object.assign(command, { maxTimeMS: session.transaction.options.maxTimeMS }); } - function commandHandler(error?: Error, result?: Document) { + function commandHandler(error?: Error) { if (commandName !== 'commitTransaction') { session.transaction.transition(TxnState.TRANSACTION_ABORTED); if (session.loadBalanced) { @@ -746,7 +746,7 @@ function endTransaction( } } - callback(error, result); + callback(error); } if (session.transaction.recoveryToken) { @@ -761,7 +761,7 @@ function endTransaction( readPreference: ReadPreference.primary, bypassPinningCheck: true }), - (error, result) => { + error => { if (command.abortTransaction) { // always unpin on abort regardless of command outcome session.unpin(); @@ -789,7 +789,7 @@ function endTransaction( ); } - commandHandler(error, result); + commandHandler(error); } ); } diff --git a/test/integration/transactions/transactions.test.ts b/test/integration/transactions/transactions.test.ts index 5169fd6dce..c05bead536 100644 --- a/test/integration/transactions/transactions.test.ts +++ b/test/integration/transactions/transactions.test.ts @@ -229,6 +229,39 @@ describe('Transactions', function () { }); }); + context('when completing a transaction', () => { + let client: MongoClient; + beforeEach(async function () { + client = this.configuration.newClient(); + }); + + afterEach(async function () { + await client.close(); + }); + + it( + 'commitTransaction() resolves void', + { requires: { mongodb: '>=4.2.0', topology: '!single' } }, + async () => + client.withSession(async session => + session.withTransaction(async session => { + expect(await session.commitTransaction()).to.be.undefined; + }) + ) + ); + + it( + 'abortTransaction() resolves void', + { requires: { mongodb: '>=4.2.0', topology: '!single' } }, + async () => + client.withSession(async session => + session.withTransaction(async session => { + expect(await session.abortTransaction()).to.be.undefined; + }) + ) + ); + }); + describe('TransientTransactionError', function () { it('should have a TransientTransactionError label inside of a transaction', { metadata: { requires: { topology: 'replicaset', mongodb: '>=4.0.0' } },