Skip to content

Commit 71c5936

Browse files
authored
feat(NODE-4961)!: remove command result from commit and abort transaction APIs (#3784)
1 parent ada1f75 commit 71c5936

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/sessions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,14 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
413413
/**
414414
* Commits the currently active transaction in this session.
415415
*/
416-
async commitTransaction(): Promise<Document> {
416+
async commitTransaction(): Promise<void> {
417417
return endTransactionAsync(this, 'commitTransaction');
418418
}
419419

420420
/**
421421
* Aborts the currently active transaction in this session.
422422
*/
423-
async abortTransaction(): Promise<Document> {
423+
async abortTransaction(): Promise<void> {
424424
return endTransactionAsync(this, 'abortTransaction');
425425
}
426426

@@ -636,14 +636,14 @@ const endTransactionAsync = promisify(
636636
endTransaction as (
637637
session: ClientSession,
638638
commandName: 'abortTransaction' | 'commitTransaction',
639-
callback: (error: Error, result: Document) => void
639+
callback: (error: Error) => void
640640
) => void
641641
);
642642

643643
function endTransaction(
644644
session: ClientSession,
645645
commandName: 'abortTransaction' | 'commitTransaction',
646-
callback: Callback<Document>
646+
callback: Callback<void>
647647
) {
648648
// handle any initial problematic cases
649649
const txnState = session.transaction.state;
@@ -717,7 +717,7 @@ function endTransaction(
717717
Object.assign(command, { maxTimeMS: session.transaction.options.maxTimeMS });
718718
}
719719

720-
function commandHandler(error?: Error, result?: Document) {
720+
function commandHandler(error?: Error) {
721721
if (commandName !== 'commitTransaction') {
722722
session.transaction.transition(TxnState.TRANSACTION_ABORTED);
723723
if (session.loadBalanced) {
@@ -746,7 +746,7 @@ function endTransaction(
746746
}
747747
}
748748

749-
callback(error, result);
749+
callback(error);
750750
}
751751

752752
if (session.transaction.recoveryToken) {
@@ -761,7 +761,7 @@ function endTransaction(
761761
readPreference: ReadPreference.primary,
762762
bypassPinningCheck: true
763763
}),
764-
(error, result) => {
764+
error => {
765765
if (command.abortTransaction) {
766766
// always unpin on abort regardless of command outcome
767767
session.unpin();
@@ -789,7 +789,7 @@ function endTransaction(
789789
);
790790
}
791791

792-
commandHandler(error, result);
792+
commandHandler(error);
793793
}
794794
);
795795
}

test/integration/transactions/transactions.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,39 @@ describe('Transactions', function () {
229229
});
230230
});
231231

232+
context('when completing a transaction', () => {
233+
let client: MongoClient;
234+
beforeEach(async function () {
235+
client = this.configuration.newClient();
236+
});
237+
238+
afterEach(async function () {
239+
await client.close();
240+
});
241+
242+
it(
243+
'commitTransaction() resolves void',
244+
{ requires: { mongodb: '>=4.2.0', topology: '!single' } },
245+
async () =>
246+
client.withSession(async session =>
247+
session.withTransaction(async session => {
248+
expect(await session.commitTransaction()).to.be.undefined;
249+
})
250+
)
251+
);
252+
253+
it(
254+
'abortTransaction() resolves void',
255+
{ requires: { mongodb: '>=4.2.0', topology: '!single' } },
256+
async () =>
257+
client.withSession(async session =>
258+
session.withTransaction(async session => {
259+
expect(await session.abortTransaction()).to.be.undefined;
260+
})
261+
)
262+
);
263+
});
264+
232265
describe('TransientTransactionError', function () {
233266
it('should have a TransientTransactionError label inside of a transaction', {
234267
metadata: { requires: { topology: 'replicaset', mongodb: '>=4.0.0' } },

0 commit comments

Comments
 (0)