diff options
author | Xuerui Fa <xuerui.fa@mongodb.com> | 2020-06-01 11:58:13 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-18 00:37:49 +0000 |
commit | b44bcc8aba3e8cf386618055f796d1904d3ba0dd (patch) | |
tree | 639c4041919c9b8d2ff6b6658ce02f1476b07163 | |
parent | d57b69a04cadb876d982366274dcad124d60e211 (diff) | |
download | mongo-b44bcc8aba3e8cf386618055f796d1904d3ba0dd.tar.gz |
SERVER-48514: Separate testing 'called' and 'successful' fields for serverStatus election metrics
(cherry picked from commit 1a79855014361b5938322549758a89c1ec75e792)
-rw-r--r-- | jstests/replsets/libs/election_metrics.js | 28 | ||||
-rw-r--r-- | jstests/replsets/stepup.js | 3 |
2 files changed, 22 insertions, 9 deletions
diff --git a/jstests/replsets/libs/election_metrics.js b/jstests/replsets/libs/election_metrics.js index 36307b2117e..423aa30a678 100644 --- a/jstests/replsets/libs/election_metrics.js +++ b/jstests/replsets/libs/election_metrics.js @@ -19,18 +19,30 @@ function verifyServerStatusElectionReasonCounterValue(electionMetrics, fieldName /** * 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, expectedIncrement) { +function verifyServerStatusElectionReasonCounterChange(initialElectionMetrics, + newElectionMetrics, + fieldName, + expectedNumCalled, + expectedNumSuccessful = undefined) { + // If 'expectedNumSuccessful' is not passed in, we assume that the 'successful' field is equal + // to the 'called' field. + if (!expectedNumSuccessful) { + expectedNumSuccessful = expectedNumCalled; + } + const initialField = initialElectionMetrics[fieldName]; const newField = newElectionMetrics[fieldName]; - assert.eq(initialField["called"] + expectedIncrement, + assert.eq(initialField["called"] + expectedNumCalled, newField["called"], - `expected the 'called' field of '${fieldName}' to increase by ${expectedIncrement}`); - assert.eq( - initialField["successful"] + expectedIncrement, - newField["successful"], - `expected the 'successful' field of '${fieldName}' to increase by ${expectedIncrement}`); + `expected the 'called' field of '${fieldName}' to increase by ${expectedNumCalled}`); + assert.eq(initialField["successful"] + expectedNumSuccessful, + newField["successful"], + `expected the 'successful' field of '${fieldName}' to increase by ${ + expectedNumSuccessful}`); } /** diff --git a/jstests/replsets/stepup.js b/jstests/replsets/stepup.js index c7062a6b4f0..1c52f68e98a 100644 --- a/jstests/replsets/stepup.js +++ b/jstests/replsets/stepup.js @@ -55,7 +55,8 @@ const newSecondaryStatus = assert.commandWorked(secondary.adminCommand({serverSt verifyServerStatusElectionReasonCounterChange(initialSecondaryStatus.electionMetrics, newSecondaryStatus.electionMetrics, "stepUpCmd", - numStepUpCmds); + numStepUpCmds, /* expectedNumCalled */ + 1 /* expectedNumSuccessful */); verifyServerStatusElectionReasonCounterChange(initialSecondaryStatus.electionMetrics, newSecondaryStatus.electionMetrics, "priorityTakeover", |