jstests/noPassthrough/router_transactions_metrics.js
// Verifies the transaction server status response has the fields that we expect.
Verifies the transaction server status response has the fields that we expect.
Verifies the transaction server status response has the fields that we expect .
function verifyServerStatusFields(res) {
    const expectedFields = [
        "currentOpen",
        "currentActive",
        "currentInactive",
        "totalStarted",
        "totalAborted",
        "abortCause",
        "totalCommitted",
        "totalContactedParticipants",
        "totalParticipantsAtCommit",
        "totalRequestsTargeted",
        "commitTypes",
    ];
    assert(res.hasOwnProperty("transactions"),
           "Expected serverStatus response to have a 'transactions' field, res: " + tojson(res));
    assert.hasFields(res.transactions,
                     expectedFields,
                     "The 'transactions' field did not have all of the expected fields, res: " +
                         tojson(res.transactions));
    assert.eq(expectedFields.length,
              Object.keys(res.transactions).length,
              "the 'transactions' field had an unexpected number of fields, res: " +
                  tojson(res.transactions));
    const commitTypes = [
        "noShards",
        "singleShard",
        "singleWriteShard",
        "readOnly",
        "twoPhaseCommit",
        "recoverWithToken",
    ];
    const commitTypeFields = ["initiated", "successful", "successfulDurationMicros"];
    assert.hasFields(res.transactions.commitTypes,
                     commitTypes,
                     "The 'transactions' field did not have each expected commit type, res: " +
                         tojson(res.transactions));
    assert.eq(commitTypes.length,
              Object.keys(res.transactions.commitTypes).length,
              "the 'transactions' field had an unexpected number of commit types, res: " +
                  tojson(res.transactions));
    commitTypes.forEach((type) => {
        assert.hasFields(res.transactions.commitTypes[type],
                         commitTypeFields,
                         "commit type " + type +
                             " did not have all the expected fields, commit types: " +
                             tojson(res.transactions.commitTypes));
        assert.eq(commitTypeFields.length,
                  Object.keys(res.transactions.commitTypes[type]).length,
                  "commit type " + type + " had an unexpected number of fields, commit types: " +
                      tojson(res.transactions.commitTypes));
    });
}
function verifyServerStatusFields ( res ) { const expectedFields = [ "currentOpen" , "currentActive" , "currentInactive" , "totalStarted" , "totalAborted" , "abortCause" , "totalCommitted" , "totalContactedParticipants" , "totalParticipantsAtCommit" , "totalRequestsTargeted" , "commitTypes" , ] ; assert ( res . hasOwnProperty ( "transactions" ) , "Expected serverStatus response to have a 'transactions' field, res: " + tojson ( res ) ) ; assert . hasFields ( res . transactions , expectedFields , "The 'transactions' field did not have all of the expected fields, res: " + tojson ( res . transactions ) ) ; assert . eq ( expectedFields . length , Object . keys ( res . transactions ) . length , "the 'transactions' field had an unexpected number of fields, res: " + tojson ( res . transactions ) ) ; const commitTypes = [ "noShards" , "singleShard" , "singleWriteShard" , "readOnly" , "twoPhaseCommit" , "recoverWithToken" , ] ; const commitTypeFields = [ "initiated" , "successful" , "successfulDurationMicros" ] ; assert . hasFields ( res . transactions . commitTypes , commitTypes , "The 'transactions' field did not have each expected commit type, res: " + tojson ( res . transactions ) ) ; assert . eq ( commitTypes . length , Object . keys ( res . transactions . commitTypes ) . length , "the 'transactions' field had an unexpected number of commit types, res: " + tojson ( res . transactions ) ) ; commitTypes . forEach ( ( type ) => { assert . hasFields ( res . transactions . commitTypes [ type ] , commitTypeFields , "commit type " + type + " did not have all the expected fields, commit types: " + tojson ( res . transactions . commitTypes ) ) ; assert . eq ( commitTypeFields . length , Object . keys ( res . transactions . commitTypes [ type ] ) . length , "commit type " + type + " had an unexpected number of fields, commit types: " + tojson ( res . transactions . commitTypes ) ) ; } ) ; }
Verifies the transaction server status response has the fields that we expect.
Verifies the transaction server status response has the fields that we expect .
// Verify the "commitTypes" sub-object has the expected fields.