Repository: couchdb
Updated Branches:
  refs/heads/windsor-merge 3c7aa3ff5 -> 641de3963 (forced update)


Don't sleep mindlessly for 3s at a time

Attempting to compare the source and target update_seq values isn't
valid as any document modification on the source will permanently alter
the comparison. This changes things to just wait for the task's status
to update and reflect the source database's update sequence.

Locally this shortens the replication.js test by about 45s.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/641de396
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/641de396
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/641de396

Branch: refs/heads/windsor-merge
Commit: 641de396362a3b5e3954a1e24b92500320080ab4
Parents: caba893
Author: Paul J. Davis <paul.joseph.da...@gmail.com>
Authored: Tue Aug 12 15:15:11 2014 -0500
Committer: Paul J. Davis <paul.joseph.da...@gmail.com>
Committed: Tue Aug 12 15:16:43 2014 -0500

----------------------------------------------------------------------
 share/www/script/test/replication.js | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/641de396/share/www/script/test/replication.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/replication.js 
b/share/www/script/test/replication.js
index de62b3f..0ad9e8c 100644
--- a/share/www/script/test/replication.js
+++ b/share/www/script/test/replication.js
@@ -151,16 +151,23 @@ couchTests.replication = function(debug) {
 
 
   function waitForSeq(sourceDb, targetDb) {
-    var targetSeq,
-        sourceSeq = sourceDb.info().update_seq,
+    var sourceSeq = sourceDb.info().update_seq,
         t0 = new Date(),
         t1,
         ms = 3000;
 
     do {
-      targetSeq = targetDb.info().update_seq;
+      var xhr = CouchDB.request("GET", "/_active_tasks");
+      var tasks = JSON.parse(xhr.responseText);
+      for(var i = 0; i < tasks.length; i++) {
+        if(tasks[i].replication_id == repResult._local_id) {
+          if(tasks[i]["source_seq"] == sourceSeq) {
+            return;
+          }
+        }
+      }
       t1 = new Date();
-    } while (((t1 - t0) <= ms) && targetSeq < sourceSeq);
+    } while (((t1 - t0) <= ms));
   }
 
 
@@ -1166,7 +1173,7 @@ couchTests.replication = function(debug) {
 
     var rep_id = repResult._local_id;
 
-    waitForSeq(sourceDb, targetDb);
+    waitForSeq(sourceDb, targetDb, rep_id);
 
     for (j = 0; j < docs.length; j++) {
       doc = docs[j];
@@ -1204,7 +1211,7 @@ couchTests.replication = function(debug) {
     var ddoc = docs[docs.length - 1]; // design doc
     addAtt(sourceDb, ddoc, "readme.txt", att1_data, "text/plain");
 
-    waitForSeq(sourceDb, targetDb);
+    waitForSeq(sourceDb, targetDb, rep_id);
 
     var modifDocs = docs.slice(10, 15).concat([ddoc]);
     for (j = 0; j < modifDocs.length; j++) {
@@ -1249,7 +1256,7 @@ couchTests.replication = function(debug) {
     // add another attachment to the ddoc on source
     addAtt(sourceDb, ddoc, "data.dat", att2_data, "application/binary");
 
-    waitForSeq(sourceDb, targetDb);
+    waitForSeq(sourceDb, targetDb, rep_id);
 
     copy = targetDb.open(ddoc._id);
     var atts = copy._attachments;
@@ -1286,7 +1293,7 @@ couchTests.replication = function(debug) {
     var newDocs = makeDocs(25, 35);
     populateDb(sourceDb, newDocs, true);
 
-    waitForSeq(sourceDb, targetDb);
+    waitForSeq(sourceDb, targetDb, rep_id);
 
     for (j = 0; j < newDocs.length; j++) {
       doc = newDocs[j];
@@ -1306,7 +1313,7 @@ couchTests.replication = function(debug) {
     wait(1000);
     TEquals(true, sourceDb.deleteDoc(newDocs[6]).ok);
 
-    waitForSeq(sourceDb, targetDb);
+    waitForSeq(sourceDb, targetDb, rep_id);
 
     copy = targetDb.open(newDocs[0]._id);
     TEquals(null, copy);
@@ -1390,7 +1397,7 @@ couchTests.replication = function(debug) {
   }
   TEquals(true, found_task);
 
-  waitForSeq(sourceDb, targetDb);
+  waitForSeq(sourceDb, targetDb, repResult._local_id);
   T(sourceDb.open("30") !== null);
 
   // cancel replication

Reply via email to