couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [17/30] couchdb commit: updated refs/heads/1963-eunit-bigcouch to d1a82df
Date Fri, 29 Aug 2014 20:33:56 GMT
Use waitForSeq and task statuses instead of sleeps

Further speedups to replication.js. Now runs in 32s on my machine vs.
the 1m45s it started at.


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

Branch: refs/heads/1963-eunit-bigcouch
Commit: 16b7ecfb9410157159f69ed59e64f359404a49a0
Parents: 641de39
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Aug 12 15:38:19 2014 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Aug 12 15:38:19 2014 -0500

----------------------------------------------------------------------
 share/www/script/test/replication.js | 66 ++++++++++++-------------------
 1 file changed, 26 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/16b7ecfb/share/www/script/test/replication.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js
index 0ad9e8c..c883374 100644
--- a/share/www/script/test/replication.js
+++ b/share/www/script/test/replication.js
@@ -97,7 +97,6 @@ couchTests.replication = function(debug) {
   function populateDb(db, docs, dontRecreateDb) {
     if (dontRecreateDb !== true) {
       db.deleteDb();
-      wait(100);
       db.createDb();
     }
     for (var i = 0; i < docs.length; i++) {
@@ -150,33 +149,37 @@ couchTests.replication = function(debug) {
   }
 
 
-  function waitForSeq(sourceDb, targetDb) {
-    var sourceSeq = sourceDb.info().update_seq,
-        t0 = new Date(),
-        t1,
-        ms = 3000;
-
+  function getTask(rep_id, delay) {
+    var t0 = new Date();
+    var t1;
     do {
       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;
-          }
+          return tasks[i];
         }
       }
       t1 = new Date();
-    } while (((t1 - t0) <= ms));
+    } while((t1 - t0) <= delay);
+
+    return null;
   }
 
 
-  function wait(ms) {
-    var t0 = new Date(), t1;
+  function waitForSeq(sourceDb, targetDb, rep_id) {
+    var sourceSeq = sourceDb.info().update_seq,
+        t0 = new Date(),
+        t1,
+        ms = 3000;
+
     do {
-      CouchDB.request("GET", "/");
+      var task = getTask(rep_id, 0);
+      if(task && task["source_seq"] == sourceSeq) {
+        return;
+      }
       t1 = new Date();
-    } while ((t1 - t0) <= ms);
+    } while (((t1 - t0) <= ms));
   }
 
 
@@ -1310,7 +1313,6 @@ couchTests.replication = function(debug) {
 
     // delete docs from source
     TEquals(true, sourceDb.deleteDoc(newDocs[0]).ok);
-    wait(1000);
     TEquals(true, sourceDb.deleteDoc(newDocs[6]).ok);
 
     waitForSeq(sourceDb, targetDb, rep_id);
@@ -1348,7 +1350,7 @@ couchTests.replication = function(debug) {
     };
     TEquals(true, sourceDb.save(doc).ok);
 
-    wait(2000);
+    waitForSeq(sourceDb, targetDb, rep_id);
     copy = targetDb.open(doc._id);
     TEquals(null, copy);
   }
@@ -1721,21 +1723,12 @@ couchTests.replication = function(debug) {
   );
   TEquals(true, repResult.ok);
   TEquals('string', typeof repResult._local_id);
+  var repId = repResult._local_id;
 
-  // Race conditions are awesome
-  wait(500);
-
-  xhr = CouchDB.request("GET", "/_active_tasks");
-  tasks = JSON.parse(xhr.responseText);
-
-  var repId;
-  for (j = 0; j < tasks.length; j++) {
-    if (tasks[j].replication_id === repResult._local_id) {
-      repId = tasks[j].replication_id;
-    }
-  }
+  var task = getTask(repId, 3000);
+  T(task != null);
 
-  TEquals(repResult._local_id, repId, "Replication found in _active_tasks");
+  TEquals(task["replication_id"], repId, "Replication found in _active_tasks");
   xhr = CouchDB.request(
     "POST", "/_replicate", {
       body: JSON.stringify({"replication_id": repId, "cancel": true}),
@@ -1743,19 +1736,12 @@ couchTests.replication = function(debug) {
   });
   TEquals(200, xhr.status, "Replication cancel request success");
 
-  xhr = CouchDB.request("GET", "/_active_tasks");
-  tasks = JSON.parse(xhr.responseText);
-  repId = null;
-  for (j = 0; j < tasks.length; j++) {
-    if (tasks[j].replication_id === repResult._local_id) {
-      repId = tasks[j].replication_id;
-    }
-  }
-  TEquals(null, repId, "Replication was canceled");
+  task = getTask(repId);
+  TEquals(null, task, "Replication was canceled");
 
   xhr = CouchDB.request(
     "POST", "/_replicate", {
-      body: JSON.stringify({"replication_id": repResult._local_id, "cancel": true}),
+      body: JSON.stringify({"replication_id": repId, "cancel": true}),
       headers: {"Content-Type": "application/json"}
   });
   TEquals(404, xhr.status, "2nd replication cancel failed");


Mime
View raw message