summaryrefslogtreecommitdiff
path: root/jstests/sharding/internal_txns/libs/fixture_helpers.js
blob: 5e418726fc6033f414f22668983f32ace128bf33 (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
function runTxnRetryOnTransientError(txnFunc) {
    assert.soon(() => {
        try {
            txnFunc();
            return true;
        } catch (e) {
            if (e.hasOwnProperty('errorLabels') &&
                e.errorLabels.includes('TransientTransactionError') &&
                e.code != ErrorCodes.NoSuchTransaction) {
                // Don't retry on a NoSuchTransaction error since it implies the transaction was
                // aborted so we should propagate the error instead.
                jsTest.log("Failed to run transaction due to a transient error " + tojson(e));
                return false;
            } else {
                throw e;
            }
        }
    });
}

function runTxnRetryOnLockTimeoutError(txnFunc) {
    assert.soon(() => {
        try {
            txnFunc();
            return true;
        } catch (e) {
            if (e.hasOwnProperty('errorLabels') &&
                e.errorLabels.includes('TransientTransactionError') &&
                e.code == ErrorCodes.LockTimeout) {
                jsTest.log("Failed to run transaction due to a transient error " + tojson(e));
                return false;
            } else {
                throw e;
            }
        }
    });
}