jstests/replsets/libs/election_metrics.js
/**
 * Verifies that the given election reason counter is incremented in the way we expect in the
 * 'electionMetrics' serverStatus section.
 *
 * The 'expectedNumSuccessful' field should be passed in when we need to distinguish between how
 * many times an election was called and how many times an election was successful.
 */
Verifies that the given election reason counter is incremented in the way we expect in the
'electionMetrics' serverStatus section.

The 'expectedNumSuccessful' field should be passed in when we need to distinguish between how
many times an election was called and how many times an election was successful.
Verifies that the given election reason counter is incremented in the way we expect in the ' electionMetrics ' serverStatus section . The ' expectedNumSuccessful ' field should be passed in when we need to distinguish between how many times an election was called and how many times an election was successful .
function verifyServerStatusElectionReasonCounterChange(initialElectionMetrics,
                                                       newElectionMetrics,
                                                       fieldName,
                                                       expectedNumCalled,
                                                       expectedNumSuccessful = undefined,
                                                       allowGreater = false) {
    if (!expectedNumSuccessful) {
        expectedNumSuccessful = expectedNumCalled;
    }
    const initialField = initialElectionMetrics[fieldName];
    const newField = newElectionMetrics[fieldName];
    const assertFunc = function(expected, actual, msg) {
        if (allowGreater) {
            assert.lte(expected, actual, msg);
        } else {
            assert.eq(expected, actual, msg);
        }
    };
    assertFunc(initialField["called"] + expectedNumCalled,
               newField["called"],
               `expected the 'called' field of '${fieldName}' to increase by ${expectedNumCalled}`);
    assertFunc(initialField["successful"] + expectedNumSuccessful,
               newField["successful"],
               `expected the 'successful' field of '${fieldName}' to increase by ${
                   expectedNumSuccessful}`);
}
function verifyServerStatusElectionReasonCounterChange ( initialElectionMetrics , newElectionMetrics , fieldName , expectedNumCalled , expectedNumSuccessful = undefined , allowGreater = false ) { if ( ! expectedNumSuccessful ) { expectedNumSuccessful = expectedNumCalled ; } const initialField = initialElectionMetrics [ fieldName ] ; const newField = newElectionMetrics [ fieldName ] ; const assertFunc = function ( expected , actual , msg ) { if ( allowGreater ) { assert . lte ( expected , actual , msg ) ; } else { assert . eq ( expected , actual , msg ) ; } } ; assertFunc ( initialField [ "called" ] + expectedNumCalled , newField [ "called" ] , ` ${ fieldName } ${ expectedNumCalled } ` ) ; assertFunc ( initialField [ "successful" ] + expectedNumSuccessful , newField [ "successful" ] , ` ${ fieldName } ${ expectedNumSuccessful } ` ) ; }
Verifies that the given election reason counter is incremented in the way we expect in the
 'electionMetrics' serverStatus section.
Verifies that the given election reason counter is incremented in the way we expect in the ' electionMetrics ' serverStatus section .
// If 'expectedNumSuccessful' is not passed in, we assume that the 'successful' field is equal // to the 'called' field.