summaryrefslogtreecommitdiff
path: root/jstests/libs/curop_helpers.js
blob: 5cbf2294f31fe07c02a872d1fd56a877fb9fe4d9 (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
// Wait until the current operation matches the filter. Returns the resulting array of operations.
function waitForCurOpByFilter(db, filter, options = {}) {
    const adminDB = db.getSiblingDB("admin");
    let results = [];
    assert.soon(
        () => {
            results = adminDB.aggregate([{$currentOp: options}, {$match: filter}]).toArray();
            return results.length > 0;
        },
        () => {
            return "Failed to find a matching op for filter: " + tojson(filter) +
                "in currentOp output: " + tojson(results);
        });
    return results;
}

// Wait until the current operation reaches the fail point "failPoint" for the given namespace
// "nss". Accepts an optional filter to apply alongside the "failpointMsg". Returns the resulting
// array of operations.
function waitForCurOpByFailPoint(db, nss, failPoint, filter = {}, options = {}) {
    const adjustedFilter = {
        $and: [{ns: nss}, filter, {$or: [{failpointMsg: failPoint}, {msg: failPoint}]}]
    };
    return waitForCurOpByFilter(db, adjustedFilter, options);
}

// Wait until the current operation reaches the fail point "failPoint" with no namespace. Returns
// the resulting array of operations.
function waitForCurOpByFailPointNoNS(db, failPoint, filter = {}, options = {}) {
    const adjustedFilter = {$and: [filter, {$or: [{failpointMsg: failPoint}, {msg: failPoint}]}]};
    return waitForCurOpByFilter(db, adjustedFilter, options);
}