Skip to content
Browse files

tst beginnings

  • Loading branch information...
1 parent 44c7aff commit 764400caa28e1063a97754e50f03c31be3726c95 @dwight dwight committed
Showing with 57 additions and 45 deletions.
  1. +41 −0 jstests/_tst.js
  2. +16 −45 jstests/dur/a_quick.js
View
41 jstests/_tst.js
@@ -0,0 +1,41 @@
+/* a general testing framework (helpers) for us in the jstests/
+
+ to use, from your test file:
+ testname="mytestname";
+ load("jstests/_tst.js");
+*/
+
+if( typeof tst == "undefined" ) {
+ tst = {}
+
+ tst.log = function (optional_msg) {
+ print("\n\nstep " + ++this._step + " " + (optional_msg || ""));
+ }
+
+ tst.success = function () {
+ print(testname + " SUCCESS");
+ }
+
+ /* diff files a and b, returning the difference (empty str if no difference) */
+ tst.diff = function(a, b) {
+ function reSlash(s) {
+ var x = s;
+ if (_isWindows()) {
+ while (1) {
+ var y = x.replace('/', '\\');
+ if (y == x)
+ break;
+ x = y;
+ }
+ }
+ return x;
+ }
+ a = reSlash(a);
+ b = reSlash(b);
+ print("diff " + a + " " + b);
+ return run("diff", a, b);
+ }
+}
+
+print(testname + " BEGIN");
+tst._step = 0;
View
61 jstests/dur/a_quick.js
@@ -11,49 +11,20 @@ load("jstests/_tst.js");
var path1 = "/data/db/quicknodur";
var path2 = "/data/db/quickdur";
-function runDiff(a, b) {
- function reSlash(s) {
- var x = s;
- if (_isWindows()) {
- while (1) {
- var y = x.replace('/', '\\');
- if (y == x)
- break;
- x = y;
- }
- }
- return x;
- }
- a = reSlash(a);
- b = reSlash(b);
- print("diff " + a + " " + b);
- return run("diff", a, b);
-}
-
-var step = 1;
-function log(str) {
- if (str)
- print("\n\nstep " + step++ + " " + str);
- else
- print("\n\nstep " + step++);
-}
-
-//stopMongo(30000, 9);
-
// non-durable version
-log("start mongod without dur");
+tst.log("start mongod without dur");
var conn = startMongodEmpty("--port", 30000, "--dbpath", path1, "--nodur");
-log("without dur work");
+tst.log("without dur work");
var d = conn.getDB("test");
d.foo.insert({ _id:123 });
d.getLastError();
-log("stop without dur");
+tst.log("stop without dur");
stopMongod(30000);
// durable version
-log("start mongod with dur");
+tst.log("start mongod with dur");
var conn = startMongodEmpty("--port", 30001, "--dbpath", path2, "--dur", "--durOptions", 8);
-log("with dur work");
+tst.log("with dur work");
var d = conn.getDB("test");
d.foo.insert({ _id: 123 });
d.getLastError(); // wait
@@ -61,11 +32,11 @@ d.getLastError(); // wait
// we could actually do getlasterror fsync:1 now, but maybe this is agood
// as it will assure that commits happen on a timely basis. a bunch of the other dur/*js
// tests use fsync
-log("sleep a bit for a group commit");
+tst.log("sleep a bit for a group commit");
sleep(500);
// kill the process hard
-log("kill -9 mongod");
+tst.log("kill -9 mongod");
stopMongod(30001, /*signal*/9);
// journal file should be present, and non-empty as we killed hard
@@ -85,21 +56,21 @@ if (files.some(function (f) { return f.name.indexOf("lsn") >= 0; })) {
}
// restart and recover
-log("restart and recover");
+tst.log("restart and recover");
var conn = startMongodNoReset("--port", 30002, "--dbpath", path2, "--dur", "--durOptions", 8);
-log("check data results");
+tst.log("check data results");
var d = conn.getDB("test");
print("count:" + d.foo.count());
assert(d.foo.count() == 1, "count 1");
-log("stop");
+tst.log("stop");
stopMongod(30002);
// stopMongod is asynchronous unfortunately. wait some.
// sleep(2000);
// at this point, after clean shutdown, there should be no journal files
-log("check no journal files");
+tst.log("check no journal files");
var jfiles = listFiles(path2 + "/journal");
if (jfiles.length) {
print("sleeping more waiting for mongod to stop");
@@ -114,8 +85,8 @@ if (jfiles.length) {
}
}
-log("check data matches");
-var diff = runDiff(path1 + "/test.ns", path2 + "/test.ns");
+tst.log("check data matches");
+var diff = tst.diff(path1 + "/test.ns", path2 + "/test.ns");
print("diff of .ns files returns:" + diff);
function showfiles() {
@@ -132,11 +103,11 @@ if (diff != "") {
assert(diff == "", "error test.ns files differ");
}
-var diff = runDiff(path1 + "/test.0", path2 + "/test.0");
+var diff = tst.diff(path1 + "/test.0", path2 + "/test.0");
print("diff of .0 files returns:" + diff);
if (diff != "") {
showfiles();
assert(diff == "", "error test.0 files differ");
}
-
-print("quick.js SUCCESS");
+
+tst.success();

0 comments on commit 764400c

Please sign in to comment.
Something went wrong with that request. Please try again.