Skip to content

Commit

Permalink
tst beginnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Jan 3, 2011
1 parent 44c7aff commit 764400c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 45 deletions.
41 changes: 41 additions & 0 deletions jstests/_tst.js
Original file line number Original file line Diff line number Diff line change
@@ -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;
61 changes: 16 additions & 45 deletions jstests/dur/a_quick.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,61 +11,32 @@ load("jstests/_tst.js");
var path1 = "/data/db/quicknodur"; var path1 = "/data/db/quicknodur";
var path2 = "/data/db/quickdur"; 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 // non-durable version
log("start mongod without dur"); tst.log("start mongod without dur");
var conn = startMongodEmpty("--port", 30000, "--dbpath", path1, "--nodur"); var conn = startMongodEmpty("--port", 30000, "--dbpath", path1, "--nodur");
log("without dur work"); tst.log("without dur work");
var d = conn.getDB("test"); var d = conn.getDB("test");
d.foo.insert({ _id:123 }); d.foo.insert({ _id:123 });
d.getLastError(); d.getLastError();
log("stop without dur"); tst.log("stop without dur");
stopMongod(30000); stopMongod(30000);


// durable version // durable version
log("start mongod with dur"); tst.log("start mongod with dur");
var conn = startMongodEmpty("--port", 30001, "--dbpath", path2, "--dur", "--durOptions", 8); var conn = startMongodEmpty("--port", 30001, "--dbpath", path2, "--dur", "--durOptions", 8);
log("with dur work"); tst.log("with dur work");
var d = conn.getDB("test"); var d = conn.getDB("test");
d.foo.insert({ _id: 123 }); d.foo.insert({ _id: 123 });
d.getLastError(); // wait d.getLastError(); // wait


// we could actually do getlasterror fsync:1 now, but maybe this is agood // 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 // as it will assure that commits happen on a timely basis. a bunch of the other dur/*js
// tests use fsync // tests use fsync
log("sleep a bit for a group commit"); tst.log("sleep a bit for a group commit");
sleep(500); sleep(500);


// kill the process hard // kill the process hard
log("kill -9 mongod"); tst.log("kill -9 mongod");
stopMongod(30001, /*signal*/9); stopMongod(30001, /*signal*/9);


// journal file should be present, and non-empty as we killed hard // journal file should be present, and non-empty as we killed hard
Expand All @@ -85,21 +56,21 @@ if (files.some(function (f) { return f.name.indexOf("lsn") >= 0; })) {
} }


// restart and recover // restart and recover
log("restart and recover"); tst.log("restart and recover");
var conn = startMongodNoReset("--port", 30002, "--dbpath", path2, "--dur", "--durOptions", 8); var conn = startMongodNoReset("--port", 30002, "--dbpath", path2, "--dur", "--durOptions", 8);
log("check data results"); tst.log("check data results");
var d = conn.getDB("test"); var d = conn.getDB("test");
print("count:" + d.foo.count()); print("count:" + d.foo.count());
assert(d.foo.count() == 1, "count 1"); assert(d.foo.count() == 1, "count 1");


log("stop"); tst.log("stop");
stopMongod(30002); stopMongod(30002);


// stopMongod is asynchronous unfortunately. wait some. // stopMongod is asynchronous unfortunately. wait some.
// sleep(2000); // sleep(2000);


// at this point, after clean shutdown, there should be no journal files // 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"); var jfiles = listFiles(path2 + "/journal");
if (jfiles.length) { if (jfiles.length) {
print("sleeping more waiting for mongod to stop"); print("sleeping more waiting for mongod to stop");
Expand All @@ -114,8 +85,8 @@ if (jfiles.length) {
} }
} }


log("check data matches"); tst.log("check data matches");
var diff = runDiff(path1 + "/test.ns", path2 + "/test.ns"); var diff = tst.diff(path1 + "/test.ns", path2 + "/test.ns");
print("diff of .ns files returns:" + diff); print("diff of .ns files returns:" + diff);


function showfiles() { function showfiles() {
Expand All @@ -132,11 +103,11 @@ if (diff != "") {
assert(diff == "", "error test.ns files differ"); 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); print("diff of .0 files returns:" + diff);
if (diff != "") { if (diff != "") {
showfiles(); showfiles();
assert(diff == "", "error test.0 files differ"); assert(diff == "", "error test.0 files differ");
} }

print("quick.js SUCCESS"); tst.success();

0 comments on commit 764400c

Please sign in to comment.