summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2020-09-25 18:50:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-29 16:08:39 +0000
commitcd0315d1b733a4d94fe1e26d6ccddb8b625b711f (patch)
tree5b653be8e8a3480a90c0e6c94c8aed92a8b7c790
parent379c0116b694d8d88ec096170e703fe3d0119e55 (diff)
downloadmongo-cd0315d1b733a4d94fe1e26d6ccddb8b625b711f.tar.gz
SERVER-50611 Relax assertion around number of elections in priority_takeover_one_node_higher_priority.js
-rw-r--r--jstests/replsets/libs/election_metrics.js26
-rw-r--r--jstests/replsets/priority_takeover_one_node_higher_priority.js12
2 files changed, 26 insertions, 12 deletions
diff --git a/jstests/replsets/libs/election_metrics.js b/jstests/replsets/libs/election_metrics.js
index 423aa30a678..51724f274cb 100644
--- a/jstests/replsets/libs/election_metrics.js
+++ b/jstests/replsets/libs/election_metrics.js
@@ -27,7 +27,8 @@ function verifyServerStatusElectionReasonCounterChange(initialElectionMetrics,
newElectionMetrics,
fieldName,
expectedNumCalled,
- expectedNumSuccessful = undefined) {
+ expectedNumSuccessful = undefined,
+ allowGreater = false) {
// If 'expectedNumSuccessful' is not passed in, we assume that the 'successful' field is equal
// to the 'called' field.
if (!expectedNumSuccessful) {
@@ -36,13 +37,22 @@ function verifyServerStatusElectionReasonCounterChange(initialElectionMetrics,
const initialField = initialElectionMetrics[fieldName];
const newField = newElectionMetrics[fieldName];
- assert.eq(initialField["called"] + expectedNumCalled,
- newField["called"],
- `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}`);
+
+ const assertFunc = function(left, right, msg) {
+ if (allowGreater) {
+ assert.gte(left, right, msg);
+ } else {
+ assert.eq(left, right, 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}`);
}
/**
diff --git a/jstests/replsets/priority_takeover_one_node_higher_priority.js b/jstests/replsets/priority_takeover_one_node_higher_priority.js
index 24482229c1d..3a9b0248f29 100644
--- a/jstests/replsets/priority_takeover_one_node_higher_priority.js
+++ b/jstests/replsets/priority_takeover_one_node_higher_priority.js
@@ -38,14 +38,18 @@ replSet.waitForState(replSet.nodes[1], ReplSetTest.State.PRIMARY);
// Unfreeze node 0 so it can seek election.
assert.commandWorked(primary.adminCommand({replSetFreeze: 0}));
-// Eventually node 0 will stand for election again because it has a higher priorty.
+// Eventually node 0 will stand for election again because it has a higher priority.
replSet.waitForState(replSet.nodes[0], ReplSetTest.State.PRIMARY);
// Check that both the 'called' and 'successful' fields of the 'priorityTakeover' election
-// reason counter have been incremented in serverStatus.
+// reason counter have been incremented in serverStatus. We allow an increase of more than 1
+// in case a slow election causes a priority takeover to fail.
const newPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
-verifyServerStatusElectionReasonCounterChange(
- initialPrimaryStatus.electionMetrics, newPrimaryStatus.electionMetrics, "priorityTakeover", 1);
+verifyServerStatusElectionReasonCounterChange(initialPrimaryStatus.electionMetrics,
+ newPrimaryStatus.electionMetrics,
+ "priorityTakeover",
+ 1,
+ true /* allowGreater */);
replSet.stopSet();
})();