Skip to content

Commit

Permalink
Added test to check closing on remote disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenCow committed Sep 12, 2013
1 parent 11051c8 commit bcd3775
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/eventsource_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,43 @@ describe('Reconnection', function() {
});
});

it('is stopped when server goes down and eventsource is being closed', function(done) {
createServer(["data: Hello\n\n"], function(closeFirstServer) {
var es = new EventSource('http://localhost:' + port);
es.reconnectInterval = 0;

es.onmessage = function(m) {
assert.equal("Hello", m.data);
closeFirstServer(function() {
// The server has closed down. es.onerror should now get called,
// because es's remote connection was dropped.
});
};

es.onerror = function(source) {

// We received an error because the remote connection was closed.
// We close es, so we do not want es to reconnect.
es.close();

createServer(["data: World\n\n"], function(closeSecondServer) {
es.onmessage = second;

function second(m) {
// We received a message even though we closed es.
assert.ok(false);
}

setTimeout(function() {
// We have not received any message within 100ms, we can
// presume this works correctly.
closeSecondServer(done);
},100);
});
};
});
});

it('is not attempted when server responds with HTTP 204', function(done) {
createServer(["data: Hello\n\n"], function(closeFirstServer) {
var es = new EventSource('http://localhost:' + port);
Expand Down

0 comments on commit bcd3775

Please sign in to comment.