diff options
Diffstat (limited to 'share/www/script/test/delayed_commits.js')
-rw-r--r-- | share/www/script/test/delayed_commits.js | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/share/www/script/test/delayed_commits.js b/share/www/script/test/delayed_commits.js index 0ead2d84..1cc0b339 100644 --- a/share/www/script/test/delayed_commits.js +++ b/share/www/script/test/delayed_commits.js @@ -15,43 +15,43 @@ couchTests.delayed_commits = function(debug) { db.deleteDb(); db.createDb(); if (debug) debugger; - + // By default, couchdb doesn't fully commit documents to disk right away, - // it waits about a second to batch the full commit flush along with any + // it waits about a second to batch the full commit flush along with any // other updates. If it crashes or is restarted you may lose the most // recent commits. - + T(db.save({_id:"1",a:2,b:4}).ok); T(db.open("1") != null); - + restartServer(); - + T(db.open("1") == null); // lost the update. // note if we waited > 1 sec before the restart, the doc would likely // commit. - - + + // Retry the same thing but with full commits on. - + var db2 = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"true"}); - + T(db2.save({_id:"1",a:2,b:4}).ok); T(db2.open("1") != null); - + restartServer(); - + T(db2.open("1") != null); - + // You can update but without committing immediately, and then ensure // everything is commited in the last step. - + T(db.save({_id:"2",a:2,b:4}).ok); T(db.open("2") != null); T(db.ensureFullCommit().ok); restartServer(); - + T(db.open("2") != null); - + // However, it's possible even when flushed, that the server crashed between // the update and the commit, and you don't want to check to make sure // every doc you updated actually made it to disk. So record the instance @@ -59,37 +59,37 @@ couchTests.delayed_commits = function(debug) { // after the flush (the instance start time is returned by the flush // operation). if they are the same, we know everything was updated // safely. - + // First try it with a crash. - + var instanceStartTime = db.info().instance_start_time; - + T(db.save({_id:"3",a:2,b:4}).ok); T(db.open("3") != null); - + restartServer(); - + var commitResult = db.ensureFullCommit(); T(commitResult.ok && commitResult.instance_start_time != instanceStartTime); // start times don't match, meaning the server lost our change - + T(db.open("3") == null); // yup lost it - + // retry with no server restart - + var instanceStartTime = db.info().instance_start_time; - + T(db.save({_id:"4",a:2,b:4}).ok); T(db.open("4") != null); - + var commitResult = db.ensureFullCommit(); T(commitResult.ok && commitResult.instance_start_time == instanceStartTime); // Successful commit, start times match! - + restartServer(); - + T(db.open("4") != null); - + // Now test that when we exceed the max_dbs_open, pending commits are safely // written. T(db.save({_id:"5",foo:"bar"}).ok); @@ -111,5 +111,5 @@ couchTests.delayed_commits = function(debug) { dbi.deleteDb(); } }); - + }; |