Skip to content

Commit

Permalink
Set client status before unregisterClient call
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Jul 25, 2019
1 parent 6fb4d14 commit 32beb65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ Client.prototype.close = function (done) {
conn.removeAllListeners('error')
conn.on('error', nop)

that.connected = false
that.disconnected = true

if (that.broker.clients[that.id]) {
that.broker.unregisterClient(that)
}
Expand All @@ -290,9 +293,6 @@ Client.prototype.close = function (done) {
conn.end()
}

that.connected = false
that.disconnected = true

if (typeof done === 'function') {
done()
}
Expand Down
9 changes: 6 additions & 3 deletions test/will.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ test('delete the will in the persistence after publish', function (t) {
test('delivers a will with authorization', function (t) {
let authorized = false
var opts = {}
var broker = aedes({ authorizePublish: (_1, _2, callback) => { authorized = true; callback(null) } })
// willConnect populates opts with a will
var s = willConnect(setup(aedes({ authorizePublish: (_1, _2, callback) => { authorized = true; callback(null) } })), opts)
var s = willConnect(setup(broker), opts)

s.broker.on('clientDisconnect', function () {
t.end()
s.broker.on('clientDisconnect', function (client) {
t.equal(client.connected, false)
t.equal(client.disconnected, true)
})

s.broker.mq.on('mywill', function (packet, cb) {
Expand All @@ -189,6 +191,7 @@ test('delivers a will with authorization', function (t) {
process.nextTick(function () {
s.conn.destroy()
})
broker.on('closed', t.end.bind(t))
})

test('delivers a will waits for authorization', function (t) {
Expand Down

0 comments on commit 32beb65

Please sign in to comment.