mongo/jstests/libs/killed_session_util.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

38 lines
1.2 KiB
JavaScript

/**
* Utilities for testing when sessions are killed.
*/
export var KilledSessionUtil = (function () {
// Returns if the code is one that could come from a session being killed.
function isKilledSessionCode(code) {
return (
code === ErrorCodes.Interrupted ||
code === ErrorCodes.CursorKilled ||
code === ErrorCodes.CursorNotFound ||
code === ErrorCodes.QueryPlanKilled
);
}
function hasKilledSessionError(errOrRes) {
let hasOriginalErrorKilledSessionCode =
errOrRes.code == ErrorCodes.TransactionParticipantFailedUnyield
? isKilledSessionCode(errOrRes.originalError.code)
: false;
return (
hasOriginalErrorKilledSessionCode ||
isKilledSessionCode(errOrRes.code) ||
(Array.isArray(errOrRes.writeErrors) &&
errOrRes.writeErrors.every((writeError) => isKilledSessionCode(writeError.code)))
);
}
function hasKilledSessionWCError(res) {
return res.writeConcernError && isKilledSessionCode(res.writeConcernError.code);
}
return {
isKilledSessionCode,
hasKilledSessionError,
hasKilledSessionWCError,
};
})();