summaryrefslogtreecommitdiff
path: root/jstests/slow1
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2014-12-02 15:43:13 -0500
committerEric Milkie <milkie@10gen.com>2014-12-03 12:58:24 -0500
commit5598c216ca28234735999ca25b3f6f9a030f51e6 (patch)
treef3acde451094af8436a321e8a8780439e2998353 /jstests/slow1
parent225aa52bd22a54d06cc090e7cd4b0fd4312213b2 (diff)
downloadmongo-5598c216ca28234735999ca25b3f6f9a030f51e6.tar.gz
SERVER-16391 archor primary in replset tests, or make agnostic to primary node
Diffstat (limited to 'jstests/slow1')
-rw-r--r--jstests/slow1/replsets_priority1.js150
1 files changed, 75 insertions, 75 deletions
diff --git a/jstests/slow1/replsets_priority1.js b/jstests/slow1/replsets_priority1.js
index e6587de99ce..db28539ebe4 100644
--- a/jstests/slow1/replsets_priority1.js
+++ b/jstests/slow1/replsets_priority1.js
@@ -1,6 +1,6 @@
// come up with random priorities and make sure that the right member gets
-// elected. then kill that member and make sure then next one gets elected.
-
+// elected. then kill that member and make sure the next one gets elected.
+
print("\n\n\nreplsets_priority1.js BEGIN\n");
load("jstests/replsets/rslib.js");
@@ -29,65 +29,65 @@ var everyoneOkSoon = function() {
}
return ok;
}, tojson(status));
-};
-
-var checkPrimaryIs = function (node) {
-
- print("nreplsets_priority1.js checkPrimaryIs(" + node + ")");
-
- var status;
-
- assert.soon(function () {
- var ok = true;
-
- try {
- status = master.adminCommand({ replSetGetStatus: 1 });
- }
- catch (e) {
- print(e);
- print("nreplsets_priority1.js checkPrimaryIs reconnecting");
- reconnect(master);
- status = master.adminCommand({ replSetGetStatus: 1 });
- }
-
- var str = "goal: " + node.host + "==1 states: ";
- if (!status || !status.members) {
- return false;
- }
- status.members.forEach(function (m) {
- str += m.name + ": " + m.state + " ";
-
- if (m.name == node.host) {
- ok &= m.state == 1;
- }
- else {
- ok &= m.state != 1 || (m.state == 1 && m.health == 0);
- }
- });
- print();
- print(str);
- print();
-
- occasionally(function () {
- print("\nstatus:");
- printjson(status);
- print();
- }, 15);
-
- return ok;
- }, node.host + '==1', 60000, 1000);
-
- everyoneOkSoon();
};
-everyoneOkSoon();
-
+var checkPrimaryIs = function (node) {
+
+ print("nreplsets_priority1.js checkPrimaryIs(" + node + ")");
+
+ var status;
+
+ assert.soon(function () {
+ var ok = true;
+
+ try {
+ status = master.adminCommand({ replSetGetStatus: 1 });
+ }
+ catch (e) {
+ print(e);
+ print("nreplsets_priority1.js checkPrimaryIs reconnecting");
+ reconnect(master);
+ status = master.adminCommand({ replSetGetStatus: 1 });
+ }
+
+ var str = "goal: " + node.host + "==1 states: ";
+ if (!status || !status.members) {
+ return false;
+ }
+ status.members.forEach(function (m) {
+ str += m.name + ": " + m.state + " ";
+
+ if (m.name == node.host) {
+ ok &= m.state == 1;
+ }
+ else {
+ ok &= m.state != 1 || (m.state == 1 && m.health == 0);
+ }
+ });
+ print();
+ print(str);
+ print();
+
+ occasionally(function () {
+ print("\nstatus:");
+ printjson(status);
+ print();
+ }, 15);
+
+ return ok;
+ }, node.host + '==1', 60000, 1000);
+
+ everyoneOkSoon();
+};
+
+everyoneOkSoon();
+
print("\n\nreplsets_priority1.js initial sync");
// intial sync
master.getDB("foo").bar.insert({x:1});
-rs.awaitReplication();
-
+rs.awaitReplication();
+
print("\n\nreplsets_priority1.js starting loop");
var n = 5;
@@ -102,8 +102,8 @@ for (i=0; i<n; i++) {
var version = config.version;
config.version++;
- for (var j=0; j<config.members.length; j++) {
- var priority = Math.random() * 100;
+ for (var j=0; j<config.members.length; j++) {
+ var priority = Math.random() * 100;
print("random priority : " + priority);
config.members[j].priority = priority;
@@ -119,8 +119,8 @@ for (i=0; i<n; i++) {
if (!second || config.members[j].priority > second.priority) {
second = config.members[j];
}
- }
-
+ }
+
print("\n\nreplsets_priority1.js max is " + max.host + " with priority " + max.priority + ", reconfiguring...");
var count = 0;
@@ -138,20 +138,20 @@ for (i=0; i<n; i++) {
version = master.getDB("local").system.replset.findOne().version;
}
- catch (e) {
+ catch (e) {
print("nreplsets_priority1.js Caught exception: " + e);
}
count++;
- }
-
+ }
+
print("\nreplsets_priority1.js wait for 2 slaves");
assert.soon(function() {
rs.getMaster();
return rs.liveNodes.slaves.length == 2;
- }, "2 slaves");
-
+ }, "2 slaves");
+
print("\nreplsets_priority1.js wait for new config version " + config.version);
assert.soon(function() {
@@ -161,20 +161,20 @@ for (i=0; i<n; i++) {
rs.liveNodes.slaves[1].setSlaveOk();
versions[1] = rs.liveNodes.slaves[1].getDB("local").system.replset.findOne().version;
return versions[0] == config.version && versions[1] == config.version;
- });
-
- print("replsets_priority1.js awaitReplication");
+ });
+
+ print("replsets_priority1.js awaitReplication");
// the reconfiguration needs to be replicated! the hb sends it out
// separately from the repl
- rs.awaitReplication();
-
+ rs.awaitReplication();
+
print("reconfigured. Checking statuses.");
- checkPrimaryIs(max);
-
- print("rs.stop");
-
+ checkPrimaryIs(max);
+
+ print("rs.stop");
+
rs.stop(max._id);
var master = rs.getMaster();
@@ -182,8 +182,8 @@ for (i=0; i<n; i++) {
print("\nkilled max primary. Checking statuses.");
print("second is "+second.host+" with priority "+second.priority);
- checkPrimaryIs(second);
-
+ checkPrimaryIs(second);
+
print("restart max " + max._id);
rs.restart(max._id);