jstests/noPassthrough/router_transactions_metrics.js
// Verifies the transaction values in the server status response match the provided values.
Verifies the transaction values in the server status response match the provided values.
Verifies the transaction values in the server status response match the provided values .
function verifyServerStatusValues(st, expectedStats) {
    const res = assert.commandWorked(st.s.adminCommand({serverStatus: 1}));
    verifyServerStatusFields(res);
    const stats = res.transactions;
    assert.eq(expectedStats.currentOpen,
              stats.currentOpen,
              "unexpected currentOpen, res: " + tojson(stats));
    assert.eq(expectedStats.currentActive,
              stats.currentActive,
              "unexpected currentActive, res: " + tojson(stats));
    assert.eq(expectedStats.currentInactive,
              stats.currentInactive,
              "unexpected currentInactive, res: " + tojson(stats));
    assert.eq(expectedStats.totalStarted,
              stats.totalStarted,
              "unexpected totalStarted, res: " + tojson(stats));
    assert.eq(expectedStats.totalAborted,
              stats.totalAborted,
              "unexpected totalAborted, res: " + tojson(stats));
    assert.eq(expectedStats.totalCommitted,
              stats.totalCommitted,
              "unexpected totalCommitted, res: " + tojson(stats));
    assert.eq(expectedStats.totalContactedParticipants,
              stats.totalContactedParticipants,
              "unexpected totalContactedParticipants, res: " + tojson(stats));
    assert.eq(expectedStats.totalParticipantsAtCommit,
              stats.totalParticipantsAtCommit,
              "unexpected totalParticipantsAtCommit, res: " + tojson(stats));
    assert.eq(expectedStats.totalRequestsTargeted,
              stats.totalRequestsTargeted,
              "unexpected totalRequestsTargeted, res: " + tojson(stats));
    const commitTypes = res.transactions.commitTypes;
    const noShardsCommit = "noShards";
    Object.keys(commitTypes).forEach((commitType) => {
        assert.eq(
            expectedStats.commitTypes[commitType].initiated,
            commitTypes[commitType].initiated,
            "unexpected initiated for " + commitType + ", commit types: " + tojson(commitTypes));
        assert.eq(
            expectedStats.commitTypes[commitType].successful,
            commitTypes[commitType].successful,
            "unexpected successful for " + commitType + ", commit types: " + tojson(commitTypes));
        assert.lte(expectedStats.commitTypes[commitType].successfulDurationMicros,
                   commitTypes[commitType].successfulDurationMicros,
                   "unexpected successfulDurationMicros for " + commitType +
                       ", commit types: " + tojson(commitTypes));
        expectedStats.commitTypes[commitType].successfulDurationMicros =
            commitTypes[commitType].successfulDurationMicros;
        if (commitTypes[commitType].successful != 0 && commitType !== noShardsCommit) {
            assert.gt(commitTypes[commitType].successfulDurationMicros,
                      0,
                      "unexpected successfulDurationMicros for " + commitType +
                          ", commit types: " + tojson(commitTypes));
        }
    });
    const abortCause = res.transactions.abortCause;
    Object.keys(abortCause).forEach((cause) => {
        assert.eq(expectedStats.abortCause[cause],
                  abortCause[cause],
                  "unexpected abortCause for " + cause + ", res: " + tojson(stats));
    });
    assert.eq(
        Object.keys(abortCause).length,
        Object.keys(expectedStats.abortCause).length,
        "the 'transactions' field had an unexpected number of abort causes, res: " + tojson(stats));
}
function verifyServerStatusValues ( st , expectedStats ) { const res = assert . commandWorked ( st . s . adminCommand ( { serverStatus : 1 } ) ) ; verifyServerStatusFields ( res ) ; const stats = res . transactions ; assert . eq ( expectedStats . currentOpen , stats . currentOpen , "unexpected currentOpen, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . currentActive , stats . currentActive , "unexpected currentActive, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . currentInactive , stats . currentInactive , "unexpected currentInactive, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalStarted , stats . totalStarted , "unexpected totalStarted, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalAborted , stats . totalAborted , "unexpected totalAborted, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalCommitted , stats . totalCommitted , "unexpected totalCommitted, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalContactedParticipants , stats . totalContactedParticipants , "unexpected totalContactedParticipants, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalParticipantsAtCommit , stats . totalParticipantsAtCommit , "unexpected totalParticipantsAtCommit, res: " + tojson ( stats ) ) ; assert . eq ( expectedStats . totalRequestsTargeted , stats . totalRequestsTargeted , "unexpected totalRequestsTargeted, res: " + tojson ( stats ) ) ; const commitTypes = res . transactions . commitTypes ; const noShardsCommit = "noShards" ; Object . keys ( commitTypes ) . forEach ( ( commitType ) => { assert . eq ( expectedStats . commitTypes [ commitType ] . initiated , commitTypes [ commitType ] . initiated , "unexpected initiated for " + commitType + ", commit types: " + tojson ( commitTypes ) ) ; assert . eq ( expectedStats . commitTypes [ commitType ] . successful , commitTypes [ commitType ] . successful , "unexpected successful for " + commitType + ", commit types: " + tojson ( commitTypes ) ) ; assert . lte ( expectedStats . commitTypes [ commitType ] . successfulDurationMicros , commitTypes [ commitType ] . successfulDurationMicros , "unexpected successfulDurationMicros for " + commitType + ", commit types: " + tojson ( commitTypes ) ) ; expectedStats . commitTypes [ commitType ] . successfulDurationMicros = commitTypes [ commitType ] . successfulDurationMicros ; if ( commitTypes [ commitType ] . successful != 0 && commitType !== noShardsCommit ) { assert . gt ( commitTypes [ commitType ] . successfulDurationMicros , 0 , "unexpected successfulDurationMicros for " + commitType + ", commit types: " + tojson ( commitTypes ) ) ; } } ) ; const abortCause = res . transactions . abortCause ; Object . keys ( abortCause ) . forEach ( ( cause ) => { assert . eq ( expectedStats . abortCause [ cause ] , abortCause [ cause ] , "unexpected abortCause for " + cause + ", res: " + tojson ( stats ) ) ; } ) ; assert . eq ( Object . keys ( abortCause ) . length , Object . keys ( expectedStats . abortCause ) . length , "the 'transactions' field had an unexpected number of abort causes, res: " + tojson ( stats ) ) ; }
Verifies the transaction values in the server status response match the provided values.
Verifies the transaction values in the server status response match the provided values .