summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-01-29 14:43:20 -0500
committerBenety Goh <benety@mongodb.com>2016-02-01 10:48:04 -0500
commit6d38a1f04849ae593c0101bfcebb1b017f831003 (patch)
tree8269b9c4a7777c36da62ccde5b8ec20875338e44
parentc5932d8130a8a7fb6bcc9ef43a62f8fa2266ebce (diff)
downloadmongo-6d38a1f04849ae593c0101bfcebb1b017f831003.tar.gz
SERVER-22362 better bookkeeping of primary and secondary nodes at the beginning of every election_timing.js test cycle
(cherry picked from commit e75d147610ca7b704c7d7a429d4d2d06b8a99603)
-rw-r--r--jstests/libs/election_timing_test.js25
1 files changed, 10 insertions, 15 deletions
diff --git a/jstests/libs/election_timing_test.js b/jstests/libs/election_timing_test.js
index e20c9391b75..8ff4daf8bbb 100644
--- a/jstests/libs/election_timing_test.js
+++ b/jstests/libs/election_timing_test.js
@@ -80,25 +80,27 @@ ElectionTimingTest.prototype._runTimingTest = function() {
// Create and populate a collection.
var primary = this.rst.getPrimary();
- var coll = primary.getCollection(collectionName);
- var secondary = this.rst.getSecondary();
this.electionTimeoutLimitMillis =
ElectionTimingTest.calculateElectionTimeoutLimitMillis(primary);
jsTestLog('Election timeout limit: ' + this.electionTimeoutLimitMillis + ' ms');
+ var coll = primary.getCollection(collectionName);
for (var i = 0; i < 100; i++) {
assert.writeOK(coll.insert({_id: i,
x: i * 3,
arbitraryStr: "this is a string"}));
}
- // Make sure the secondaries are up then await replication.
- this.rst.awaitSecondaryNodes();
- this.rst.awaitReplication();
-
// Run the election tests on this ReplSetTest instance.
+ var secondary;
for (var cycle = 0; cycle < this.testCycles; cycle++) {
+ // Wait for replication.
+ this.rst.awaitSecondaryNodes();
+ this.rst.awaitReplication();
+ primary = this.rst.getPrimary();
+ secondary = this.rst.getSecondary();
+
jsTestLog("Starting test: " + this.name + " run: " + run + " cycle: " + cycle);
var oldElectionId = primary.getDB("admin").isMaster().electionId;
@@ -158,13 +160,6 @@ ElectionTimingTest.prototype._runTimingTest = function() {
break;
}
}
- // Wait for replication. When there are only two nodes in the set,
- // the previous primary should be given a chance to catch up or
- // else there will be rollbacks after the next election cycle.
- this.rst.awaitSecondaryNodes();
- this.rst.awaitReplication();
- primary = newPrimary;
- secondary = this.rst.getSecondary();
}
this.testResults.push(cycleData);
this.rst.stopSet();
@@ -210,7 +205,7 @@ ElectionTimingTest.calculateElectionTimeoutLimitMillis = function(primary) {
var protocolVersion = config.hasOwnProperty("protocolVersion") ? config.protocolVersion : 0;
var electionTimeoutMillis = 0;
var electionTimeoutOffsetLimitFraction = 0;
- if (protocolVersion == 0) {
+ if (protocolVersion === 0) {
electionTimeoutMillis = 30000; // from TopologyCoordinatorImpl::VoteLease::leaseTime
electionTimeoutOffsetLimitFraction = 0;
} else {
@@ -229,4 +224,4 @@ ElectionTimingTest.calculateElectionTimeoutLimitMillis = function(primary) {
applierDrainWaitMillis +
assertSoonIntervalMillis;
return electionTimeoutLimitMillis;
-}
+};