Skip to content

Commit

Permalink
[Endpoint] test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FGRibreau committed Feb 22, 2014
1 parent f2336c8 commit 4bb71b4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
14 changes: 11 additions & 3 deletions lib/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ _.extend(Endpoint.prototype, EventEmitter.prototype, {
this.socket.on('close', this.onClose);
this.socket.on('error', this.onError);

this.socket.setTimeout(0);
this.socket.setNoDelay();
this.socket.setTimeout(0, function(){
console.log('timeout');
});

this.socket.setNoDelay(true);
this.socket.setKeepAlive(true, 30);
},

Expand Down Expand Up @@ -183,9 +186,14 @@ _.extend(Endpoint.prototype, EventEmitter.prototype, {
},

onError: function(err){
console.log('onerror', err);
Endpoint.log.error('[Endpoint] Error ' + (err ? err.message : ''));
this.socket.destroy(); // End the socket
this.emit('close', err ? err.message : '');
try{
this.onClose(err ? err.message : '');
}catch(err){
console.error('err::onError', err);
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "redsmin",
"description": "Redsmin proxy daemon for the Redsmin service",
"version": "1.1.0",
"version": "1.1.1",
"keywords": [
"redis",
"redis-gui",
Expand Down
29 changes: 19 additions & 10 deletions test/Endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,24 @@ exports['Endpoint'] = {
},

'onError': function(t){
var E = this.E;
t.expect(4);
E.socket = {
end: function(){
t.ok(true, "called");
}
};
t.doesNotThrow(function(){E.onError();});
t.doesNotThrow(function(){E.onError('ok');});
t.done();
t.expect(1);

var E = this.E
, hostname = 'ssl.redsmin.dev'
, port = 433;

E.on('connect', function(){
var spy = sinon.spy(E.socket, "destroy");
E.socket.emit('error');

E.removeAllListeners();
E.socket.removeAllListeners();

t.ok(spy.called, 'destroy called');
t.done();
});

E.handshaken = true;
E.connect(port, hostname);
}
};

0 comments on commit 4bb71b4

Please sign in to comment.