summaryrefslogtreecommitdiff
path: root/jstests/tool
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2015-02-26 06:18:34 -0500
committermatt dannenberg <matt.dannenberg@10gen.com>2015-02-26 10:29:19 -0500
commit0524c8becac7d0824d618dbec8ed49322e596b2a (patch)
tree3982112d7ab8579b9dabc38a9f8080682575029c /jstests/tool
parenta0c4f1ffffb5fd6523ccc2feb3ffec6c2882e64f (diff)
downloadmongo-0524c8becac7d0824d618dbec8ed49322e596b2a.tar.gz
make tool_replset.js more resilient against certain failures
Diffstat (limited to 'jstests/tool')
-rw-r--r--jstests/tool/tool_replset.js111
1 files changed, 56 insertions, 55 deletions
diff --git a/jstests/tool/tool_replset.js b/jstests/tool/tool_replset.js
index 62e1dba8c62..b5e8059045d 100644
--- a/jstests/tool/tool_replset.js
+++ b/jstests/tool/tool_replset.js
@@ -14,76 +14,77 @@
* 12. Make sure that the oplog was played
*/
-// Load utility methods for replica set tests
-load("jstests/replsets/rslib.js");
+(function() {
+ "use strict";
-print("starting the replica set")
+ var replTest = new ReplSetTest({ name: 'tool_replset', nodes: 2, oplogSize: 5 });
+ var nodes = replTest.startSet();
+ var config = replTest.getReplSetConfig();
+ config.members[0].priority = 3;
+ config.members[1].priority = 0;
+ replTest.initiate(config);
+ var master = replTest.getMaster();
+ assert.eq(nodes[0], master, "incorrect master elected");
+ for (var i = 0; i < 100; i++) {
+ assert.writeOK(master.getDB("foo").bar.insert({ a: i }));
+ }
+ replTest.awaitReplication();
-var replTest = new ReplSetTest({ name: 'tool_replset', nodes: 2, oplogSize: 5 });
-var nodes = replTest.startSet();
-replTest.initiate();
-var master = replTest.getMaster();
-for (var i = 0; i < 100; i++) {
- master.getDB("foo").bar.insert({ a: i });
-}
-replTest.awaitReplication();
+ var replSetConnString = "tool_replset/127.0.0.1:" + replTest.ports[0] +
+ ",127.0.0.1:" + replTest.ports[1];
-var replSetConnString = "tool_replset/127.0.0.1:" + replTest.ports[0] +
- ",127.0.0.1:" + replTest.ports[1];
+ // Test with mongodump/mongorestore
+ print("dump the db");
+ var data = MongoRunner.dataDir + "/tool_replset-dump1/";
+ runMongoProgram("mongodump", "--host", replSetConnString, "--out", data);
-// Test with mongodump/mongorestore
-print("dump the db");
-var data = MongoRunner.dataDir + "/tool_replset-dump1/";
-runMongoProgram("mongodump", "--host", replSetConnString, "--out", data);
+ print("db successfully dumped, dropping now");
+ master.getDB("foo").dropDatabase();
+ replTest.awaitReplication();
-print("db successfully dumped, dropping now");
-master.getDB("foo").dropDatabase();
-replTest.awaitReplication();
+ print("restore the db");
+ runMongoProgram("mongorestore", "--host", replSetConnString, "--dir", data);
-print("restore the db");
-runMongoProgram("mongorestore", "--host", replSetConnString, "--dir", data);
+ print("db successfully restored, checking count")
+ var x = master.getDB("foo").getCollection("bar").count();
+ assert.eq(x, 100, "mongorestore should have successfully restored the collection");
-print("db successfully restored, checking count")
-var x = master.getDB("foo").getCollection("bar").count();
-assert.eq(x, 100, "mongorestore should have successfully restored the collection");
+ replTest.awaitReplication();
-replTest.awaitReplication();
+ // Test with mongoexport/mongoimport
+ print("export the collection");
+ var extFile = MongoRunner.dataDir + "/tool_replset/export";
+ runMongoProgram("mongoexport", "--host", replSetConnString, "--out", extFile,
+ "-d", "foo", "-c", "bar");
-// Test with mongoexport/mongoimport
-print("export the collection");
-var extFile = MongoRunner.dataDir + "/tool_replset/export";
-runMongoProgram("mongoexport", "--host", replSetConnString, "--out", extFile,
- "-d", "foo", "-c", "bar");
+ print("collection successfully exported, dropping now");
+ master.getDB("foo").getCollection("bar").drop();
+ replTest.awaitReplication();
-print("collection successfully exported, dropping now");
-master.getDB("foo").getCollection("bar").drop();
-replTest.awaitReplication();
+ print("import the collection");
+ runMongoProgram("mongoimport", "--host", replSetConnString, "--file", extFile,
+ "-d", "foo", "-c", "bar");
-print("import the collection");
-runMongoProgram("mongoimport", "--host", replSetConnString, "--file", extFile,
- "-d", "foo", "-c", "bar");
+ var x = master.getDB("foo").getCollection("bar").count();
+ assert.eq(x, 100, "mongoimport should have successfully imported the collection");
+ var doc = {_id: 5, x: 17};
+ var oplogEntry = {ts: new Timestamp(), "op": "i", "ns": "foo.bar", "o": doc, "v": NumberInt(2)}
+ assert.writeOK(master.getDB("local").oplog.rs.insert(oplogEntry));
-var x = master.getDB("foo").getCollection("bar").count();
-assert.eq(x, 100, "mongoimport should have successfully imported the collection");
+ assert.eq(100, master.getDB("foo").getCollection("bar").count(), "count before running " +
+ "mongooplog was not 100 as expected");
-// Test with mongooplog
-var doc = { _id : 5, x : 17 };
-master.getDB("local").oplog.rs.insert({ ts : new Timestamp(), "op" : "i", "ns" : "foo.bar",
- "o" : doc, "v" : NumberInt(2) });
+ runMongoProgram("mongooplog" , "--from", "127.0.0.1:" + replTest.ports[0],
+ "--host", replSetConnString);
-assert.eq(100, master.getDB("foo").getCollection("bar").count(), "count before running mongooplog " +
- "was not 100 as expected");
+ print("finished running mongooplog to replay the oplog")
-runMongoProgram("mongooplog" , "--from", "127.0.0.1:" + replTest.ports[0],
- "--host", replSetConnString);
+ assert.eq(101, master.getDB("foo").getCollection("bar").count(), "count after running " +
+ "mongooplog was not 101 as expected")
-print("running mongooplog to replay the oplog")
+ print("all tests successful, stopping replica set")
-assert.eq(101, master.getDB("foo").getCollection("bar").count(), "count after running mongooplog " +
- "was not 101 as expected")
+ replTest.stopSet();
-print("all tests successful, stopping replica set")
-
-replTest.stopSet();
-
-print("replica set stopped, test complete")
+ print("replica set stopped, test complete")
+}());