fix: end stream connection

This commit is contained in:
Vratislav Kalenda 2018-04-04 22:28:38 +02:00 committed by Brian C
parent 860928e2d5
commit 0902d145f4
3 changed files with 13 additions and 3 deletions

View File

@ -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) {

View File

@ -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 () {

View File

@ -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.end = function() {
p.closed = true;
}
p.setKeepAlive = function () {}
p.closed = false;
p.writable = true
const createClient = function () {