You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/07/10 16:51:09 UTC
[36/50] couchdb commit: updated refs/heads/master to 6526051
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/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/10dcfc5d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/10dcfc5d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/10dcfc5d
Branch: refs/heads/master
Commit: 10dcfc5de8b39a420bfe0f2562be8a3946d30d67
Parents: 7439833
Author: Damjan Georgievski <gd...@gmail.com>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Robert Newson <rn...@apache.org>
Committed: Wed May 21 17:08:11 2014 +0100
----------------------------------------------------------------------
share/www/script/test/changes.js | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/10dcfc5d/share/www/script/test/changes.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index 00944f7..f35ce39 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/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();