jstests/sharding/allow_partial_results_nshards.js
// Helper to find a logline containing all the specified fields. Throws if no such line exists.
Helper to find a logline containing all the specified fields. Throws if no such line exists.
Helper to find a logline containing all the specified fields . Throws if no such line exists .
function assertMatchingLogLineExists(fields) {
    function escapeRegex(input) {
        return (typeof input === "string" ? input.replace(/[\^\$\\\.\*\+\?\(\)\[\]\{\}]/g, '\\$&')
                                          : input);
    }
    function lineMatches(line, fields) {
        const fieldNames = Object.keys(fields);
        return fieldNames.every((fieldName) => {
            const fieldValue = fields[fieldName];
            let regex;
            if (isJsonLogNoConn()) {
                const regexDecimal = "\"" + escapeRegex(fieldName) + "\":? ?(" +
                    escapeRegex(checkLog.formatAsJsonLogLine(fieldValue, false, true)) + "|" +
                    escapeRegex(checkLog.formatAsJsonLogLine(fieldValue, true, true)) + ")";
                const regexNoDecimal = "\"" + escapeRegex(fieldName) + "\":? ?(" +
                    escapeRegex(checkLog.formatAsJsonLogLine(fieldValue, false, false)) + "|" +
                    escapeRegex(checkLog.formatAsJsonLogLine(fieldValue, true, false)) + ")";
                const matchDecimal = line.match(regexDecimal);
                const matchNoDecimal = line.match(regexNoDecimal);
                return (matchDecimal && matchDecimal[0]) || (matchNoDecimal && matchNoDecimal[0]);
            } else {
                const regex = escapeRegex(fieldName) + ":? ?(" +
                    escapeRegex(checkLog.formatAsLogLine(fieldValue)) + "|" +
                    escapeRegex(checkLog.formatAsLogLine(fieldValue, true)) + ")";
                const match = line.match(regex);
                return match && match[0];
            }
        });
    }
    const globalLog = assert.commandWorked(mongosDB.adminCommand({getLog: "global"}));
    assert(globalLog.log.find((line) => lineMatches(line, fields)), "failed to find log line ");
}
function assertMatchingLogLineExists ( fields ) { function escapeRegex ( input ) { return ( typeof input === "string" ? input . replace ( / [\^\$\\\.\*\+\?\(\)\[\]\{\}] / g , '\\$&' ) : input ) ; } function lineMatches ( line , fields ) { const fieldNames = Object . keys ( fields ) ; return fieldNames . every ( ( fieldName ) => { const fieldValue = fields [ fieldName ] ; let regex ; if ( isJsonLogNoConn ( ) ) { const regexDecimal = "\"" + escapeRegex ( fieldName ) + "\":? ?(" + escapeRegex ( checkLog . formatAsJsonLogLine ( fieldValue , false , true ) ) + "|" + escapeRegex ( checkLog . formatAsJsonLogLine ( fieldValue , true , true ) ) + ")" ; const regexNoDecimal = "\"" + escapeRegex ( fieldName ) + "\":? ?(" + escapeRegex ( checkLog . formatAsJsonLogLine ( fieldValue , false , false ) ) + "|" + escapeRegex ( checkLog . formatAsJsonLogLine ( fieldValue , true , false ) ) + ")" ; const matchDecimal = line . match ( regexDecimal ) ; const matchNoDecimal = line . match ( regexNoDecimal ) ; return ( matchDecimal && matchDecimal [ 0 ] ) || ( matchNoDecimal && matchNoDecimal [ 0 ] ) ; } else { const regex = escapeRegex ( fieldName ) + ":? ?(" + escapeRegex ( checkLog . formatAsLogLine ( fieldValue ) ) + "|" + escapeRegex ( checkLog . formatAsLogLine ( fieldValue , true ) ) + ")" ; const match = line . match ( regex ) ; return match && match [ 0 ] ; } } ) ; } const globalLog = assert . commandWorked ( mongosDB . adminCommand ( { getLog : "global" } ) ) ; assert ( globalLog . log . find ( ( line ) => lineMatches ( line , fields ) ) , "failed to find log line " ) ; }
Helper to find a logline containing all the specified fields.
Helper to find a logline containing all the specified fields .