Skip to content

Commit 974f01c

Browse files
refactor helper function to be simpler
1 parent a32367f commit 974f01c

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/sessions.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@ async function attemptTransactionCommit<T>(
570570
!isMaxTimeMSExpiredError(err)
571571
) {
572572
if (err.hasErrorLabel(MongoErrorLabel.UnknownTransactionCommitResult)) {
573-
return attemptTransactionCommit(session, startTime, fn, result, options);
573+
return await attemptTransactionCommit(session, startTime, fn, result, options);
574574
}
575575

576576
if (err.hasErrorLabel(MongoErrorLabel.TransientTransactionError)) {
577-
return attemptTransaction(session, startTime, fn, options);
577+
return await attemptTransaction(session, startTime, fn, options);
578578
}
579579
}
580580

@@ -748,13 +748,28 @@ async function endTransaction(
748748
command.recoveryToken = session.transaction.recoveryToken;
749749
}
750750

751-
const handleFirstCommandAttempt = async (error?: Error) => {
751+
const partiallyHandleFirstCommandAttempt = async () => {
752752
if (command.abortTransaction) {
753753
// always unpin on abort regardless of command outcome
754754
session.unpin();
755755
}
756+
};
756757

757-
if (error instanceof MongoError && isRetryableWriteError(error)) {
758+
try {
759+
// send the command
760+
await executeOperation(
761+
session.client,
762+
new RunAdminCommandOperation(command, {
763+
session,
764+
readPreference: ReadPreference.primary,
765+
bypassPinningCheck: true
766+
})
767+
);
768+
await partiallyHandleFirstCommandAttempt();
769+
commandHandler();
770+
} catch (err) {
771+
await partiallyHandleFirstCommandAttempt();
772+
if (err instanceof MongoError && isRetryableWriteError(err)) {
758773
// SPEC-1185: apply majority write concern when retrying commitTransaction
759774
if (command.commitTransaction) {
760775
// per txns spec, must unpin session in this case
@@ -775,27 +790,12 @@ async function endTransaction(
775790
})
776791
);
777792
commandHandler();
778-
} catch (e) {
779-
commandHandler(e);
793+
} catch (err2) {
794+
commandHandler(err2);
780795
}
781-
return;
796+
} else {
797+
commandHandler(err);
782798
}
783-
commandHandler(error);
784-
};
785-
786-
try {
787-
// send the command
788-
await executeOperation(
789-
session.client,
790-
new RunAdminCommandOperation(command, {
791-
session,
792-
readPreference: ReadPreference.primary,
793-
bypassPinningCheck: true
794-
})
795-
);
796-
await handleFirstCommandAttempt();
797-
} catch (e) {
798-
await handleFirstCommandAttempt(e);
799799
}
800800
}
801801

test/integration/transactions-convenient-api/transactions-convenient-api.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SKIPPED_TESTS = [
99
'withTransaction succeeds if callback aborts'
1010
];
1111

12-
describe.only('Transactions Convenient API Spec Unified Tests', function () {
12+
describe('Transactions Convenient API Spec Unified Tests', function () {
1313
beforeEach(function () {
1414
if (this.configuration.topologyType === 'LoadBalanced') {
1515
if (this.currentTest) {

test/integration/transactions/transactions.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SKIPPED_TESTS = [
1414
'causal consistency disabled'
1515
];
1616

17-
describe.only('Transactions Spec Unified Tests', function () {
17+
describe('Transactions Spec Unified Tests', function () {
1818
runUnifiedSuite(loadSpecTests(path.join('transactions', 'unified')), test => {
1919
return SKIPPED_TESTS.includes(test.description)
2020
? 'TODO(NODE-5924/NODE-5925): Skipping failing transaction tests'

0 commit comments

Comments
 (0)