couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r780539 - in /couchdb/trunk: share/www/script/test/changes.js src/couchdb/couch_httpd_db.erl
Date Mon, 01 Jun 2009 00:27:28 GMT
Author: damien
Date: Mon Jun  1 00:27:28 2009
New Revision: 780539

URL: http://svn.apache.org/viewvc?rev=780539&view=rev
Log:
Added tests for heartbeat and timeout options in the _changes api.

Modified:
    couchdb/trunk/share/www/script/test/changes.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/changes.js?rev=780539&r1=780538&r2=780539&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/changes.js (original)
+++ couchdb/trunk/share/www/script/test/changes.js Mon Jun  1 00:27:28 2009
@@ -30,6 +30,12 @@
   
   T(resp.results.length == 1 && resp.last_seq==1)
   T(resp.results[0].changes[0].rev == docFoo._rev)
+
+  
+  req = CouchDB.request("GET", "/test_suite_db/_changes?continuous=true&timeout=10");
+  var resp = JSON.parse(req.responseText);
+  T(resp.results.length == 1 && resp.last_seq==1)
+  T(resp.results[0].changes[0].rev == docFoo._rev)
   
   var xhr;
   
@@ -43,7 +49,7 @@
     // with real async support.
     
     var sleep = function(msecs) {
-      // by making a slow sync request, weallows the waiting XHR request data
+      // 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);
@@ -55,6 +61,7 @@
       }
       return JSON.parse(line);
     }
+    
   
     xhr.open("GET", "/test_suite_db/_changes?continuous=true", true);
     xhr.send("");
@@ -89,6 +96,19 @@
     T(change.seq == 3);
     T(change.id == "baz");
     T(change.changes[0].rev == docBaz._rev);
+    
+    
+    xhr = CouchDB.newXhr();
   
+    //verify the hearbeat newlines are sent
+    xhr.open("GET", "/test_suite_db/_changes?continuous=true&heartbeat=10", true);
+    xhr.send("");
+    
+    sleep(100);
+    
+    var str = xhr.responseText;
+    
+    T(str.charAt(str.length - 1) == "\n")
+    T(str.charAt(str.length - 2) == "\n")
   }
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=780539&r1=780538&r2=780539&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Mon Jun  1 00:27:28 2009
@@ -119,7 +119,8 @@
         {ok, Db2} = couch_db:open(DbName, [{user_ctx, UserCtx}]),
         keep_sending_changes(Req, Resp, Db2, EndSeq, Prepend2, Timeout, TimeoutFun);
     stop ->
-        send_chunk(Resp, io_lib:format("\n],\n\"last_seq\":~w}\n", [EndSeq]))
+        send_chunk(Resp, io_lib:format("\n],\n\"last_seq\":~w}\n", [EndSeq])),
+        send_chunk(Resp, "")
     end.
 
 send_changes(Req, Resp, Db, StartSeq, Prepend0) ->



Mime
View raw message