You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2010/06/02 14:24:40 UTC

svn commit: r950530 - in /couchdb/branches/0.11.x: etc/couchdb/default.ini.tpl.in share/www/script/test/changes.js share/www/script/test/oauth.js share/www/script/test/stats.js src/couchdb/couch_httpd_misc_handlers.erl

Author: jan
Date: Wed Jun  2 12:24:39 2010
New Revision: 950530

URL: http://svn.apache.org/viewvc?rev=950530&view=rev
Log:
Merge r930430 from trunk:

Removed _sleep from all tests. replaced with loops that spin until a condition is true. Makes tests faster and less likely to fail sporadically.

Modified:
    couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
    couchdb/branches/0.11.x/share/www/script/test/changes.js
    couchdb/branches/0.11.x/share/www/script/test/oauth.js
    couchdb/branches/0.11.x/share/www/script/test/stats.js
    couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl

Modified: couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in?rev=950530&r1=950529&r2=950530&view=diff
==============================================================================
--- couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in Wed Jun  2 12:24:39 2010
@@ -65,7 +65,6 @@ _uuids = {couch_httpd_misc_handlers, han
 _restart = {couch_httpd_misc_handlers, handle_restart_req}
 _stats = {couch_httpd_stats_handlers, handle_stats_req}
 _log = {couch_httpd_misc_handlers, handle_log_req}
-_sleep = {couch_httpd_misc_handlers, handle_sleep_req}
 _session = {couch_httpd_auth, handle_session_req}
 _oauth = {couch_httpd_oauth, handle_oauth_req}
 

Modified: couchdb/branches/0.11.x/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/changes.js?rev=950530&r1=950529&r2=950530&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/changes.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/changes.js Wed Jun  2 12:24:39 2010
@@ -76,44 +76,45 @@ couchTests.changes = function(debug) {
     // WebKit (last checked on nightly #47686) does fail on processing
     // the async-request properly while javascript is executed.
 
-    var sleep = function(msecs) {
-      // by making a slow sync request, we allow the waiting XHR request data
-      // to be received.
-      var req = CouchDB.request("GET", "/_sleep?time=" + msecs);
-      T(JSON.parse(req.responseText).ok == true);
-    }
-
     xhr.open("GET", "/test_suite_db/_changes?feed=continuous", true);
     xhr.send("");
 
     var docBar = {_id:"bar", bar:1};
     db.save(docBar);
+    
+    while(true) {
+         var lines = xhr.responseText.split("\n");
+         try {
+             var change1 = JSON.parse(lines[0]);
+             var change2 = JSON.parse(lines[1]);
+             break;
+         } catch (e) {}
+         db.info() // sync http req allow async req to happen
+    }
 
-    sleep(100);
-    var lines = xhr.responseText.split("\n");
-  
-    var change = JSON.parse(lines[0]);
-
-    T(change.seq == 1)
-    T(change.id == "foo")
-
-    change = JSON.parse(lines[1]);
-
-    T(change.seq == 2)
-    T(change.id == "bar")
-    T(change.changes[0].rev == docBar._rev)
-
+    T(change1.seq == 1)
+    T(change1.id == "foo")
+    
+    T(change2.seq == 2)
+    T(change2.id == "bar")
+    T(change2.changes[0].rev == docBar._rev)
+    
+    
     var docBaz = {_id:"baz", baz:1};
     db.save(docBaz);
 
-    sleep(100);
-    var lines = xhr.responseText.split("\n");
-
-    change = JSON.parse(lines[2]);
-
-    T(change.seq == 3);
-    T(change.id == "baz");
-    T(change.changes[0].rev == docBaz._rev);
+    while(true) {
+         var lines = xhr.responseText.split("\n");
+         try {
+             var change3 = JSON.parse(lines[2]);
+             break;
+         } catch (e) {}
+         db.info() // sync http req allow async req to happen
+        
+    }
+    T(change3.seq == 3);
+    T(change3.id == "baz");
+    T(change3.changes[0].rev == docBaz._rev);
 
 
     xhr = CouchDB.newXhr();
@@ -121,10 +122,13 @@ couchTests.changes = function(debug) {
     //verify the hearbeat newlines are sent
     xhr.open("GET", "/test_suite_db/_changes?feed=continuous&heartbeat=10", true);
     xhr.send("");
-
-    sleep(100);
-
-    var str = xhr.responseText;
+    
+    str = xhr.responseText;
+    while(str.charAt(str.length - 1) != "\n" || 
+            str.charAt(str.length - 2) != "\n") {
+        db.info() // sync http req allow async req to happen
+        str = xhr.responseText;
+    }
 
     T(str.charAt(str.length - 1) == "\n")
     T(str.charAt(str.length - 2) == "\n")
@@ -135,39 +139,48 @@ couchTests.changes = function(debug) {
 
     xhr.open("GET", "/test_suite_db/_changes?feed=longpoll", true);
     xhr.send("");
-
-    sleep(100);
-    var lines = xhr.responseText.split("\n");
-    T(lines[5]=='"last_seq":3}');
-
+    
+    while(true) {
+        try {
+            var lines = xhr.responseText.split("\n");
+            if(lines[5]=='"last_seq":3}') {
+                break;
+            }
+        } catch (e) {}
+        db.info(); // sync http req allow async req to happen
+    }
+    
     xhr = CouchDB.newXhr();
 
     xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=3", true);
     xhr.send("");
 
-    sleep(100);
-
     var docBarz = {_id:"barz", bar:1};
     db.save(docBarz);
-
-    sleep(100);
-
-    var lines = xhr.responseText.split("\n");
-
+    
     var parse_changes_line = function(line) {
       if (line.charAt(line.length-1) == ",") {
-        line = line.substring(0, line.length-1);
+        var linetrimmed = line.substring(0, line.length-1);
+      } else {
+        var linetrimmed = line
       }
-      return JSON.parse(line);
+      return JSON.parse(linetrimmed);
     }
-
-    change = parse_changes_line(lines[1]);
-
+    
+    while(true) {
+        try {
+            var lines = xhr.responseText.split("\n");
+            if(lines[3]=='"last_seq":4}')
+                break;
+        } catch (e) {}
+        db.info(); // sync http req allow async req to happen
+    }
+    
+    var change = parse_changes_line(lines[1]);
     T(change.seq == 4);
     T(change.id == "barz");
     T(change.changes[0].rev == docBarz._rev);
     T(lines[3]=='"last_seq":4}');
-	
   }
   
   // test the filtered changes
@@ -211,9 +224,8 @@ couchTests.changes = function(debug) {
     // filter with longpoll
     // longpoll filters full history when run without a since seq
     xhr = CouchDB.newXhr();
-    xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop", true);
+    xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop", false);
     xhr.send("");
-    sleep(100);
     var resp = JSON.parse(xhr.responseText);
     T(resp.last_seq == 7);
     // longpoll waits until a matching change before returning
@@ -222,8 +234,15 @@ couchTests.changes = function(debug) {
     xhr.send("");
     db.save({"_id":"falsy", "bop" : ""}); // empty string is falsy
     db.save({"_id":"bingo","bop" : "bingo"});
-    sleep(100);
-    var resp = JSON.parse(xhr.responseText);
+    
+    while(true) {
+         try {
+             var resp = JSON.parse(xhr.responseText);
+             break;
+         } catch (e) {}
+         db.info() // sync http req allow async req to happen
+    }
+    
     T(resp.last_seq == 9);
     T(resp.results && resp.results.length > 0 && resp.results[0]["id"] == "bingo", "filter the correct update");
 
@@ -232,9 +251,16 @@ couchTests.changes = function(debug) {
     xhr.open("GET", "/test_suite_db/_changes?feed=continuous&filter=changes_filter/bop&timeout=200", true);
     xhr.send("");
     db.save({"_id":"rusty", "bop" : "plankton"});
-    T(db.ensureFullCommit().ok);
-    sleep(300);
-    var lines = xhr.responseText.split("\n");
+    
+    while(true) {
+         try {
+             var lines = xhr.responseText.split("\n");
+             JSON.parse(lines[3])
+             break;
+         } catch (e) {}
+         db.info() // sync http req allow async req to happen
+    }
+    
     T(JSON.parse(lines[1]).id == "bingo", lines[1]);
     T(JSON.parse(lines[2]).id == "rusty", lines[2]);
     T(JSON.parse(lines[3]).last_seq == 10, lines[3]);

Modified: couchdb/branches/0.11.x/share/www/script/test/oauth.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/oauth.js?rev=950530&r1=950529&r2=950530&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/oauth.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/oauth.js Wed Jun  2 12:24:39 2010
@@ -94,8 +94,17 @@ couchTests.oauth = function(debug) {
         headers: {"X-Couch-Persist": "false"},
         body: JSON.stringify(testadminPassword)
       });
-
-      CouchDB.request("GET", "/_sleep?time=50");
+      while (true) {
+          //loop until the couch server has processed the password
+          var xhr = CouchDB.request("GET", "http://" + host + "/_config/admins/testadmin?foo="+i,{
+              headers: {
+                "Authorization": adminBasicAuthHeaderValue()
+              }})
+          if (xhr.responseText.indexOf("\"-hashed-") == 0) {
+              break;
+          }
+          console.log("foo:" + xhr.responseText)
+      }
 
       CouchDB.newUuids(2); // so we have one to make the salt
 

Modified: couchdb/branches/0.11.x/share/www/script/test/stats.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/stats.js?rev=950530&r1=950529&r2=950530&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/stats.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/stats.js Wed Jun  2 12:24:39 2010
@@ -81,19 +81,17 @@ couchTests.stats = function(debug) {
       var pre_dbs = getStat("couchdb", "open_databases").current || 0;
       var pre_files = getStat("couchdb", "open_os_files").current || 0;
      
-      // We have to make sure that as we open the max'th database
-      // that we've waited for more than 1 second since opening
-      // the first database so that any delayed commits will be
-      // flushed.
       var triggered = false;
       var db = null;
       for(var i = 0; i < max*2; i++) {
-        try {
-          db = newDb("test_suite_db_" + i, true);
-        } catch(e) {
-          triggered = true;
-          CouchDB.request("GET", "/_sleep?time=1500");
-          db = newDb("test_suite_db_" + i, true);
+        while (true) {
+            try {
+              db = newDb("test_suite_db_" + i, true);
+              break;
+            } catch(e) {
+                // all_dbs_active error!
+              triggered = true;
+            }
         }
 
         // Trigger a delayed commit

Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl?rev=950530&r1=950529&r2=950530&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl Wed Jun  2 12:24:39 2010
@@ -15,7 +15,7 @@
 -export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2,
     handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1,
     handle_uuids_req/1,handle_config_req/1,handle_log_req/1,
-    handle_task_status_req/1,handle_sleep_req/1]).
+    handle_task_status_req/1]).
 
 -export([increment_update_seq_req/2]).
 
@@ -64,13 +64,6 @@ handle_utils_dir_req(#httpd{method='GET'
 handle_utils_dir_req(Req, _) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
-handle_sleep_req(#httpd{method='GET'}=Req) ->
-    Time = list_to_integer(couch_httpd:qs_value(Req, "time")),
-    receive snicklefart -> ok after Time -> ok end,
-    send_json(Req, {[{ok, true}]});
-handle_sleep_req(Req) ->
-    send_method_not_allowed(Req, "GET,HEAD").
-
 handle_all_dbs_req(#httpd{method='GET'}=Req) ->
     {ok, DbNames} = couch_server:all_databases(),
     send_json(Req, DbNames);