summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXuerui Fa <xuerui.fa@mongodb.com>2020-06-01 11:58:13 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-18 00:54:04 +0000
commit68874103421db895d5ad8eb54ec03420793d561f (patch)
tree1921889ea6865ec345b4d76b310a5119305a2680
parentc015b760b0da4ade7221b2a1f0ff723072420d37 (diff)
downloadmongo-68874103421db895d5ad8eb54ec03420793d561f.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.js28
-rw-r--r--jstests/replsets/stepup.js3
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 e8b9d38b5de..0d2cb76cb99 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",