Skip to content

Commit

Permalink
[minor] It should not reconnect when we've closed the connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jul 2, 2013
1 parent fe59cb4 commit 880f490
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions primus.js
Expand Up @@ -85,6 +85,8 @@ Primus.prototype.initialise = function initalise() {
});

this.on('incoming::end', function end() {
if (primus.readyState === Primus.CLOSED) return;

primus.readyState = Primus.CLOSED;

this.reconnect(function (fail, backoff) {
Expand Down
21 changes: 21 additions & 0 deletions test/transformer.base.js
Expand Up @@ -47,6 +47,14 @@ module.exports = function base(transformer) {
});
});

it('emits an `end` event when its closed', function (done) {
var socket = new Socket('http://localhost:'+ server.portnumber);

socket.on('open', function () {
socket.end();
}).on('end', done);
});

it('sends & receives messages', function (done) {
var socket = new Socket('http://localhost:'+ server.portnumber);

Expand Down Expand Up @@ -79,6 +87,19 @@ module.exports = function base(transformer) {
}
});
});

it('should not reconnect when we close the connection', function (done) {
var socket = new Socket('http://localhost:'+ server.portnumber);

socket.on('open', function (message) {
socket.end();
done();
});

socket.on('reconnect', function () {
throw new Error('fuck');
});
});
});
});
};

0 comments on commit 880f490

Please sign in to comment.