You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/07/31 23:43:34 UTC

[44/51] [abbrv] futon commit: updated refs/heads/import-master to 53a86dd

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/97e34c28
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-futon/tree/97e34c28
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-futon/diff/97e34c28

Branch: refs/heads/import-master
Commit: 97e34c28ace8668dc6a6c7221c4a51f77a15f238
Parents: 95bf167
Author: Damjan Georgievski <gd...@gmail.com>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Klaus Trainer <kl...@apache.org>
Committed: Tue May 13 14:53:42 2014 +0200

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


http://git-wip-us.apache.org/repos/asf/couchdb-futon/blob/97e34c28/script/test/changes.js
----------------------------------------------------------------------
diff --git a/script/test/changes.js b/script/test/changes.js
index 0fba9f9..b034a0b 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();