From 424b2cd6118a919f3e780c37ed59c570e525e8fe Mon Sep 17 00:00:00 2001 From: Xuerui Fa Date: Fri, 17 Apr 2020 13:28:51 -0400 Subject: SERVER-47634: Make metrics test in stepup.js more robust (cherry picked from commit 321cb6f478bd1969ef4c7a90b210a21272354f41) --- jstests/replsets/stepup.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jstests/replsets/stepup.js b/jstests/replsets/stepup.js index 026f26332b1..e8b9d38b5de 100644 --- a/jstests/replsets/stepup.js +++ b/jstests/replsets/stepup.js @@ -36,8 +36,11 @@ assert.commandWorked( // Wait for the secondary to catch up by replicating a doc to both nodes. assert.writeOK(primary.getDB("test").bar.insert({x: 3}, {writeConcern: {w: "majority"}})); -// Step up the secondary. Retry since the old primary may step down when we try to ask for its vote. +// Step up the secondary. Retry since the old primary may step down when we try to ask for its +// vote. +let numStepUpCmds = 0; assert.soonNoExcept(function() { + numStepUpCmds++; return secondary.adminCommand({replSetStepUp: 1}).ok; }); @@ -49,8 +52,10 @@ const newSecondaryStatus = assert.commandWorked(secondary.adminCommand({serverSt // Check that both the 'called' and 'successful' fields of stepUpCmd have been incremented in // serverStatus, and that they have not been incremented in any of the other election reason // counters. -verifyServerStatusElectionReasonCounterChange( - initialSecondaryStatus.electionMetrics, newSecondaryStatus.electionMetrics, "stepUpCmd", 1); +verifyServerStatusElectionReasonCounterChange(initialSecondaryStatus.electionMetrics, + newSecondaryStatus.electionMetrics, + "stepUpCmd", + numStepUpCmds); verifyServerStatusElectionReasonCounterChange(initialSecondaryStatus.electionMetrics, newSecondaryStatus.electionMetrics, "priorityTakeover", -- cgit v1.2.1