Skip to content

Commit

Permalink
fix: end stream connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vratislav authored and brianc committed May 4, 2018
1 parent 860928e commit 0902d14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/connection/outbound-sending-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
11 changes: 9 additions & 2 deletions test/unit/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 0902d14

Please sign in to comment.