jstests/noPassthrough/currentop_query.js
/**
     * Runs a set of tests to verify that currentOp will serialize objects exceeding ~1000 bytes
     * to string when the 'truncateOps' parameter is set.
     */
Runs a set of tests to verify that currentOp will serialize objects exceeding ~1000 bytes
to string when the 'truncateOps' parameter is set.
Runs a set of tests to verify that currentOp will serialize objects exceeding ~1000 bytes to string when the ' truncateOps ' parameter is set .
function runTruncationTests() {
        dropAndRecreateTestCollection();
        assert.commandWorked(coll.insert({a: 1}));
        TestData.queryFilter = {
            "1": "1".repeat(149),
            "2": "2".repeat(149),
            "3": "3".repeat(149),
            "4": "4".repeat(149),
            "5": "5".repeat(149),
            "6": "6".repeat(149),
            "7": "7".repeat(149),
        };
        var truncatedQueryString = "^\\{ find: \"currentop_query\", filter: \\{ " +
            "1: \"1{149}\", 2: \"2{149}\", 3: \"3{149}\", 4: \"4{149}\", 5: \"5{149}\", " +
            "6: \"6{149}\", 7: \"7+\\.\\.\\.";
        let currentOpFilter;
        currentOpFilter = {
            "command.$truncated": {$regex: truncatedQueryString},
            "command.comment": "currentop_query"
        };
        confirmCurrentOpContents({
            test: function(db) {
                assert.commandWorked(db.runCommand({
                    find: "currentop_query",
                    comment: "currentop_query",
                    filter: TestData.queryFilter
                }));
            },
            planSummary: "COLLSCAN",
            currentOpFilter: currentOpFilter
        });
        currentOpFilter = {
            "command.$truncated": {$regex: truncatedQueryString},
            "command.comment": {$exists: false}
        };
        confirmCurrentOpContents({
            test: function(db) {
                assert.commandWorked(
                    db.runCommand({find: "currentop_query", filter: TestData.queryFilter}));
            },
            planSummary: "COLLSCAN",
            currentOpFilter: currentOpFilter
        });
        const cmdRes = testDB.runCommand({
            find: "currentop_query",
            comment: "currentop_query",
            filter: TestData.queryFilter,
            batchSize: 0
        });
        assert.commandWorked(cmdRes);
        TestData.commandResult = cmdRes;
        currentOpFilter = {
            "command.getMore": (isRemoteShardCurOp ? {$gt: 0} : TestData.commandResult.cursor.id),
            "cursor.originatingCommand.$truncated": {$regex: truncatedQueryString},
            "cursor.originatingCommand.comment": "currentop_query"
        };
        confirmCurrentOpContents({
            test: function(db) {
                var cursor = new DBCommandCursor(db, TestData.commandResult, 5);
                assert.eq(cursor.itcount(), 0);
            },
            planSummary: "COLLSCAN",
            currentOpFilter: currentOpFilter,
        });
        delete TestData.commandResult;
        truncatedQueryString =
            "^\\{ aggregate: \"currentop_query\", pipeline: \\[ \\{ \\$match: \\{ " +
            "1: \"1{149}\", 2: \"2{149}\", 3: \"3{149}\", 4: \"4{149}\", 5: \"5{149}\", " +
            "6: \"6{149}\", 7: \"7+\\.\\.\\.";
        currentOpFilter = commandOrOriginatingCommand(
            {"$truncated": {$regex: truncatedQueryString}, "comment": "currentop_query"},
            isRemoteShardCurOp);
        confirmCurrentOpContents({
            test: function(db) {
                assert.commandWorked(db.runCommand({
                    aggregate: "currentop_query",
                    comment: "currentop_query",
                    pipeline: [{$match: TestData.queryFilter}],
                    cursor: {}
                }));
            },
            planSummary: "COLLSCAN",
            currentOpFilter: currentOpFilter,
        });
        delete TestData.queryFilter;
    }
function runTruncationTests ( ) { dropAndRecreateTestCollection ( ) ; assert . commandWorked ( coll . insert ( { a : 1 } ) ) ; TestData . queryFilter = { "1" : "1" . repeat ( 149 ) , "2" : "2" . repeat ( 149 ) , "3" : "3" . repeat ( 149 ) , "4" : "4" . repeat ( 149 ) , "5" : "5" . repeat ( 149 ) , "6" : "6" . repeat ( 149 ) , "7" : "7" . repeat ( 149 ) , } ; var truncatedQueryString = "^\\{ find: \"currentop_query\", filter: \\{ " + "1: \"1{149}\", 2: \"2{149}\", 3: \"3{149}\", 4: \"4{149}\", 5: \"5{149}\", " + "6: \"6{149}\", 7: \"7+\\.\\.\\." ; let currentOpFilter ; currentOpFilter = { "command.$truncated" : { $regex : truncatedQueryString } , "command.comment" : "currentop_query" } ; confirmCurrentOpContents ( { test : function ( db ) { assert . commandWorked ( db . runCommand ( { find : "currentop_query" , comment : "currentop_query" , filter : TestData . queryFilter } ) ) ; } , planSummary : "COLLSCAN" , currentOpFilter : currentOpFilter } ) ; currentOpFilter = { "command.$truncated" : { $regex : truncatedQueryString } , "command.comment" : { $exists : false } } ; confirmCurrentOpContents ( { test : function ( db ) { assert . commandWorked ( db . runCommand ( { find : "currentop_query" , filter : TestData . queryFilter } ) ) ; } , planSummary : "COLLSCAN" , currentOpFilter : currentOpFilter } ) ; const cmdRes = testDB . runCommand ( { find : "currentop_query" , comment : "currentop_query" , filter : TestData . queryFilter , batchSize : 0 } ) ; assert . commandWorked ( cmdRes ) ; TestData . commandResult = cmdRes ; currentOpFilter = { "command.getMore" : ( isRemoteShardCurOp ? { $gt : 0 } : TestData . commandResult . cursor . id ) , "cursor.originatingCommand.$truncated" : { $regex : truncatedQueryString } , "cursor.originatingCommand.comment" : "currentop_query" } ; confirmCurrentOpContents ( { test : function ( db ) { var cursor = new DBCommandCursor ( db , TestData . commandResult , 5 ) ; assert . eq ( cursor . itcount ( ) , 0 ) ; } , planSummary : "COLLSCAN" , currentOpFilter : currentOpFilter , } ) ; delete TestData . commandResult ; truncatedQueryString = "^\\{ aggregate: \"currentop_query\", pipeline: \\[ \\{ \\$match: \\{ " + "1: \"1{149}\", 2: \"2{149}\", 3: \"3{149}\", 4: \"4{149}\", 5: \"5{149}\", " + "6: \"6{149}\", 7: \"7+\\.\\.\\." ; currentOpFilter = commandOrOriginatingCommand ( { "$truncated" : { $regex : truncatedQueryString } , "comment" : "currentop_query" } , isRemoteShardCurOp ) ; confirmCurrentOpContents ( { test : function ( db ) { assert . commandWorked ( db . runCommand ( { aggregate : "currentop_query" , comment : "currentop_query" , pipeline : [ { $match : TestData . queryFilter } ] , cursor : { } } ) ) ; } , planSummary : "COLLSCAN" , currentOpFilter : currentOpFilter , } ) ; delete TestData . queryFilter ; }
Runs a set of tests to verify that currentOp will serialize objects exceeding ~1000 bytes
 to string when the 'truncateOps' parameter is set.
Runs a set of tests to verify that currentOp will serialize objects exceeding ~1000 bytes to string when the ' truncateOps ' parameter is set .
// When the currentOp command serializes the query object as a string, individual string // values inside it are truncated at 150 characters. To test "total length" truncation // we need to pass multiple values, each smaller than 150 bytes. // Verify that the currentOp command removes the comment field from the command while // truncating the command. Command {find: <coll>, comment: <comment>, filter: {XYZ}} should // be represented as {$truncated: "{find: <coll>, filter: {XY...", comment: <comment>}. // We put the 'comment' field before the large 'filter' in the command object so // that, when the object is truncated in the currentOp output, we can confirm that // the 'comment' field has been removed from the object and promoted to a top-level // field. // Verify that a command without the "comment" field appears as {$truncated: <string>} when // truncated by currentOp. // Verify that an originatingCommand truncated by currentOp appears as { $truncated: // <string>, comment: <string> }. // Verify that an aggregation truncated by currentOp appears as { $truncated: <string>, // comment: <string> } when a comment parameter is present.