summaryrefslogtreecommitdiff
path: root/jstests/libs/override_methods/check_for_operation_not_supported_in_transaction.js
blob: 57ab445896d88f397778141c51a769fee1f152a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * This override checks the result of runCommand to see if an OperationNotSupportedInTransaction,
 * InvalidOptions or TransientTransactionError was returned. Some FSM workloads don't check if
 * runCommand worked because it is expected to fail when certain other operations are running. We
 * want to make sure that those errors are still ignored but not OperationNotSupportedInTransaction,
 * InvalidOptions or TransientTransactionError.
 */
(function() {
"use strict";

load("jstests/libs/error_code_utils.js");
load("jstests/libs/override_methods/override_helpers.js");

function runCommandCheckForOperationNotSupportedInTransaction(
    conn, dbName, commandName, commandObj, func, makeFuncArgs) {
    let res = func.apply(conn, makeFuncArgs(commandObj));
    const isTransient = (res.errorLabels && res.errorLabels.includes('TransientTransactionError') &&
                         !includesErrorCode(res, ErrorCodes.NoSuchTransaction));

    const isNotSupported = (includesErrorCode(res, ErrorCodes.OperationNotSupportedInTransaction) ||
                            includesErrorCode(res, ErrorCodes.InvalidOptions));

    if (isTransient || isNotSupported) {
        // Generate an exception, store some info for fsm.js to inspect, and rethrow.
        try {
            assert.commandWorked(res);
        } catch (ex) {
            ex.isTransient = isTransient;
            ex.isNotSupported = isNotSupported;
            throw ex;
        }
    }

    return res;
}

OverrideHelpers.prependOverrideInParallelShell(
    "jstests/libs/override_methods/check_for_operation_not_supported_in_transaction.js");

OverrideHelpers.overrideRunCommand(runCommandCheckForOperationNotSupportedInTransaction);
})();