From 71c593685735a08d5d7503120464a7c23ba20a46 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 31 Jul 2023 11:08:59 -0400 Subject: [PATCH] feat(NODE-4961)!: remove command result from commit and abort transaction APIs (#3784) --- src/sessions.ts | 16 ++++----- .../transactions/transactions.test.ts | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) 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' } },