diff --git a/lib/connection.js b/lib/connection.js index 8744bbe32..d2cf69ece 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -309,7 +309,9 @@ Connection.prototype.end = function () { // 0x58 = 'X' this.writer.add(emptyBuffer) this._ending = true - return this.stream.write(END_BUFFER) + return this.stream.write(END_BUFFER, () => { + this.stream.end() + }) } Connection.prototype.close = function (msg, more) { diff --git a/test/unit/connection/outbound-sending-tests.js b/test/unit/connection/outbound-sending-tests.js index e9e148c14..b8b72a214 100644 --- a/test/unit/connection/outbound-sending-tests.js +++ b/test/unit/connection/outbound-sending-tests.js @@ -183,6 +183,7 @@ test('sends end command', function () { con.end() var expected = Buffer.from([0x58, 0, 0, 0, 4]) assert.received(stream, expected) + assert.equal(stream.closed, true) }) test('sends describe command', function () { diff --git a/test/unit/test-helper.js b/test/unit/test-helper.js index 6cd2d24e0..04b73f372 100644 --- a/test/unit/test-helper.js +++ b/test/unit/test-helper.js @@ -13,12 +13,19 @@ helper.sys.inherits(MemoryStream, EventEmitter) var p = MemoryStream.prototype -p.write = function (packet) { +p.write = function (packet, cb) { this.packets.push(packet) + if(cb){ + cb(); + } } -p.setKeepAlive = function () {} +p.end = function() { + p.closed = true; +} +p.setKeepAlive = function () {} +p.closed = false; p.writable = true const createClient = function () {