summaryrefslogtreecommitdiff
path: root/jstests/replsets
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2011-12-15 09:35:47 +0100
committerAntonin Kral <a.kral@bobek.cz>2011-12-15 09:35:47 +0100
commitf0d9a01bccdaeb466c12c92057914bbfef59526c (patch)
tree7679efa1f0daf7d1d906882a15dc77af6b7aef32 /jstests/replsets
parent5d342a758c6095b4d30aba0750b54f13b8916f51 (diff)
downloadmongodb-f0d9a01bccdaeb466c12c92057914bbfef59526c.tar.gz
Imported Upstream version 2.0.2
Diffstat (limited to 'jstests/replsets')
-rw-r--r--jstests/replsets/auth1.js9
-rw-r--r--jstests/replsets/auth2.js103
-rw-r--r--jstests/replsets/initial_sync3.js55
-rw-r--r--jstests/replsets/reconfig.js2
-rw-r--r--jstests/replsets/stepdown.js3
5 files changed, 135 insertions, 37 deletions
diff --git a/jstests/replsets/auth1.js b/jstests/replsets/auth1.js
index 71ab2d9..40a131a 100644
--- a/jstests/replsets/auth1.js
+++ b/jstests/replsets/auth1.js
@@ -8,11 +8,11 @@ var path = "jstests/libs/";
print("try starting mongod with auth");
-var m = runMongoProgram( "mongod", "--auth", "--port", port[4], "--dbpath", "/data/db/wrong-auth");
+var pargs = new MongodRunner( port[4], "/data/db/wrong-auth", false, false,
+ ["--auth"], {no_bind : true} );
+var m = pargs.start();
-assert.throws(function() {
- m.getDB("local").auth("__system", "");
-});
+assert.eq(m.getDB("local").auth("__system", ""), 0);
stopMongod(port[4]);
@@ -25,7 +25,6 @@ run("chmod", "644", path+"key2");
print("try starting mongod");
m = runMongoProgram( "mongod", "--keyFile", path+"key1", "--port", port[0], "--dbpath", "/data/db/" + name);
-
print("should fail with wrong permissions");
assert.eq(m, 2, "mongod should exit w/ 2: permissions too open");
stopMongod(port[0]);
diff --git a/jstests/replsets/auth2.js b/jstests/replsets/auth2.js
new file mode 100644
index 0000000..0fe1ae4
--- /dev/null
+++ b/jstests/replsets/auth2.js
@@ -0,0 +1,103 @@
+var name = "rs_auth2";
+var port = allocatePorts(3);
+var path = "jstests/libs/";
+
+print("change permissions on #1 & #2");
+run("chmod", "600", path+"key1");
+run("chmod", "600", path+"key2");
+
+var setupReplSet = function() {
+ print("start up rs");
+ var rs = new ReplSetTest({"name" : name, "nodes" : 3, "startPort" : port[0]});
+ rs.startSet();
+ rs.initiate();
+
+ print("getting master");
+ rs.getMaster();
+
+ print("getting secondaries");
+ assert.soon(function() {
+ var result1 = rs.nodes[1].getDB("admin").runCommand({isMaster: 1});
+ var result2 = rs.nodes[2].getDB("admin").runCommand({isMaster: 1});
+ return result1.secondary && result2.secondary;
+ });
+
+ return rs;
+};
+
+var checkNoAuth = function() {
+ print("without an admin user, things should work");
+
+ master.getDB("foo").bar.insert({x:1});
+ var result = master.getDB("admin").runCommand({getLastError:1});
+
+ printjson(result);
+ assert.eq(result.err, null);
+}
+
+var checkInvalidAuthStates = function() {
+ print("check that 0 is in recovering");
+ assert.soon(function() {
+ try {
+ var result = m.getDB("admin").runCommand({isMaster: 1});
+ return !result.ismaster && !result.secondary;
+ }
+ catch ( e ) {
+ print( e );
+ }
+ });
+
+ print("shut down 1, 0 still in recovering.");
+ rs.stop(1);
+ sleep(5);
+
+ assert.soon(function() {
+ var result = m.getDB("admin").runCommand({isMaster: 1});
+ return !result.ismaster && !result.secondary;
+ });
+
+ print("shut down 2, 0 becomes a secondary.");
+ rs.stop(2);
+
+ assert.soon(function() {
+ var result = m.getDB("admin").runCommand({isMaster: 1});
+ return result.secondary;
+ });
+
+ rs.restart(1, {"keyFile" : path+"key1"});
+ rs.restart(2, {"keyFile" : path+"key1"});
+};
+
+var checkValidAuthState = function() {
+ assert.soon(function() {
+ var result = m.getDB("admin").runCommand({isMaster : 1});
+ return result.secondary;
+ });
+};
+
+var rs = setupReplSet();
+var master = rs.getMaster();
+
+print("add an admin user");
+master.getDB("admin").addUser("foo","bar");
+m = rs.nodes[0];
+
+print("starting 1 and 2 with key file");
+rs.stop(1);
+rs.restart(1, {"keyFile" : path+"key1"});
+rs.stop(2);
+rs.restart(2, {"keyFile" : path+"key1"});
+
+checkInvalidAuthStates();
+
+print("restart mongod with bad keyFile");
+
+rs.stop(0);
+m = rs.restart(0, {"keyFile" : path+"key2"});
+
+checkInvalidAuthStates();
+
+rs.stop(0);
+m = rs.restart(0, {"keyFile" : path+"key1"});
+
+print("0 becomes a secondary");
diff --git a/jstests/replsets/initial_sync3.js b/jstests/replsets/initial_sync3.js
index 7f2af94..ef45581 100644
--- a/jstests/replsets/initial_sync3.js
+++ b/jstests/replsets/initial_sync3.js
@@ -1,11 +1,6 @@
/* test initial sync options
*
- * {state : 1}
- * {state : 2}
- * {name : host+":"+port}
- * {_id : 2}
- * {optime : now}
- * {optime : 1970}
+ * Make sure member can't sync from a member with a different buildIndexes setting.
*/
load("jstests/replsets/rslib.js");
@@ -14,46 +9,44 @@ var host = getHostName();
var port = allocatePorts(7);
print("Start set with three nodes");
-var replTest = new ReplSetTest( {name: name, nodes: 7} );
+var replTest = new ReplSetTest( {name: name, nodes: 3} );
var nodes = replTest.startSet();
replTest.initiate({
_id : name,
members : [
- {_id:0, host : host+":"+port[0]},
- {_id:1, host : host+":"+port[1], initialSync : {state : 1}},
- {_id:2, host : host+":"+port[2], initialSync : {state : 2}},
- {_id:3, host : host+":"+port[3], initialSync : {name : host+":"+port[2]}},
- {_id:4, host : host+":"+port[4], initialSync : {_id : 2}},
- {_id:5, host : host+":"+port[5], initialSync : {optime : new Date()}},
- {_id:6, host : host+":"+port[6], initialSync : {optime : new Date(0)}}
+ {_id:0, host : host+":"+port[0]},
+ {_id:1, host : host+":"+port[1]},
+ {_id:2, host : host+":"+port[2], priority : 0, buildIndexes : false},
]});
var master = replTest.getMaster();
print("Initial sync");
master.getDB("foo").bar.baz.insert({x:1});
+replTest.awaitReplication();
-print("Make sure everyone's secondary");
-wait(function() {
- var status = master.getDB("admin").runCommand({replSetGetStatus:1});
- occasionally(function() {
- printjson(status);
- });
+replTest.stop(0);
+replTest.stop(1);
- if (!status.members) {
- return false;
- }
+print("restart 1, clearing its data directory so it has to resync");
+replTest.start(1);
- for (i=0; i<7; i++) {
- if (status.members[i].state != 1 && status.members[i].state != 2) {
- return false;
- }
- }
- return true;
+print("make sure 1 does not become a secondary (because it cannot clone from 2)");
+sleep(10000);
+reconnect(nodes[1]);
+var result = nodes[1].getDB("admin").runCommand({isMaster : 1});
+assert(!result.ismaster, tojson(result));
+assert(!result.secondary, tojson(result));
- });
+print("bring 0 back up");
+replTest.restart(0);
-replTest.awaitReplication();
+print("now 1 should be able to initial sync");
+assert.soon(function() {
+ var result = nodes[1].getDB("admin").runCommand({isMaster : 1});
+ printjson(result);
+ return result.secondary;
+});
replTest.stopSet();
diff --git a/jstests/replsets/reconfig.js b/jstests/replsets/reconfig.js
index b7dca03..55ee505 100644
--- a/jstests/replsets/reconfig.js
+++ b/jstests/replsets/reconfig.js
@@ -64,6 +64,6 @@ result = nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2"
{_id : 0, tags : ["member0"]}
]}});
-assert(result.errmsg.match(/bad or missing host field/));
+assert(result.errmsg.match(/bad or missing host field/) , "error message doesn't match, got result:" + tojson(result) );
replTest2.stopSet();
diff --git a/jstests/replsets/stepdown.js b/jstests/replsets/stepdown.js
index 3a17b0e..67f10f9 100644
--- a/jstests/replsets/stepdown.js
+++ b/jstests/replsets/stepdown.js
@@ -36,12 +36,15 @@ printjson(result);
assert.eq(result.ok, 0);
print("\n do stepdown that should work");
+var threw = false;
try {
master.getDB("admin").runCommand({replSetStepDown: 50, force : true});
}
catch (e) {
print(e);
+ threw = true;
}
+assert(threw);
var r2 = master.getDB("admin").runCommand({ismaster : 1});
assert.eq(r2.ismaster, false);