couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [50/51] [abbrv] futon commit: updated refs/heads/import-master to 53a86dd
Date Thu, 31 Jul 2014 21:43:40 GMT
Send a real EventSource event for heartbeat

The EventSource connection can get stuck (in TCP half-open state*) and there's no way
for the client to detect that. This commit changes the way heartbeat is sent, instead of
sending a newline character, it sends an empty event of type heartbeat:

    event: heartbeat
    data:

This event doesn't have an id: field, so the client will retain its latest Last-Event-ID state.

This doesn't change the expectations of clients that used EventSource till now, because they
subscribe to the 'message' event type. To get the 'heartbeat' events a client will need to
explicitly subscribe to it:

    source.addEventListener('heartbeat', function () { /* cancel a timer that would otherwise
reconnect the source */ });

* this can happen when you suspend your laptop, on flaky internet connection, ADSL reconnect,
bad wifi signals, bad routers etc. Pretty often in a typical internet usage nowadays.


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

Branch: refs/heads/import-master
Commit: 11bc6e76c056836d93a14998463449a96feeb278
Parents: a919960
Author: Damjan Georgievski <gdamjan@gmail.com>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed May 21 17:08:11 2014 +0100

----------------------------------------------------------------------
 script/test/changes.js | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-futon/blob/11bc6e76/script/test/changes.js
----------------------------------------------------------------------
diff --git a/script/test/changes.js b/script/test/changes.js
index 00944f7..f35ce39 100644
--- a/script/test/changes.js
+++ b/script/test/changes.js
@@ -123,7 +123,7 @@ couchTests.changes = function(debug) {
 
     xhr = CouchDB.newXhr();
 
-    //verify the hearbeat newlines are sent
+    //verify the heartbeat newlines are sent
     xhr.open("GET", CouchDB.proxyUrl("/test_suite_db/_changes?feed=continuous&heartbeat=10&timeout=500"),
true);
     xhr.send("");
 
@@ -171,6 +171,25 @@ couchTests.changes = function(debug) {
       T(results[1].changes[0].rev == docBar._rev);
     }
 
+    // test that we receive EventSource heartbeat events
+    if (!!window.EventSource) {
+      var source = new EventSource(
+              "/test_suite_db/_changes?feed=eventsource&heartbeat=10");
+
+      var count_heartbeats = 0;
+      source.addEventListener('heartbeat', function () { count_heartbeats = count_heartbeats
+ 1; } , false);
+
+      waitForSuccess(function() {
+        if (count_heartbeats < 3) {
+          throw "keep waiting";
+        }
+        return true;
+      }, "eventsource-heartbeat");
+
+      T(count_heartbeats >= 3);
+      source.close();
+    }
+
     // test longpolling
     xhr = CouchDB.newXhr();
 


Mime
View raw message