diff --git a/lib/connection.js b/lib/connection.js index 44b023cb..2b004d45 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -48,6 +48,7 @@ Connection.prototype.connect = function(port, host) { this.stream.on('connect', function() { self.emit('connect'); + self.stream.setKeepAlive(true); }); this.stream.on('error', function(error) { diff --git a/test/unit/connection/startup-tests.js b/test/unit/connection/startup-tests.js index e3b41991..29212c4e 100644 --- a/test/unit/connection/startup-tests.js +++ b/test/unit/connection/startup-tests.js @@ -43,6 +43,18 @@ test('using closed stream', function() { assert.ok(hit); }); + + test('after stream emits connected event init TCP-keepalive', function() { + + var res = false; + + stream.setKeepAlive = function(bit) { + res = bit; + }; + + assert.ok(stream.emit('connect')); + assert.equal(res, true); + }); }); test('using opened stream', function() { diff --git a/test/unit/test-helper.js b/test/unit/test-helper.js index 3bcd21e0..878898d8 100644 --- a/test/unit/test-helper.js +++ b/test/unit/test-helper.js @@ -15,6 +15,8 @@ p.write = function(packet) { this.packets.push(packet); }; +p.setKeepAlive = function(){}; + p.writable = true; createClient = function() {