Skip to content

Commit

Permalink
Add a unit test, not deliver will when DISCONNECT
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Aug 11, 2019
1 parent 01eb963 commit f39b93f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/client.js
Expand Up @@ -267,8 +267,9 @@ Client.prototype.close = function (done) {
}
}
})
that.will = null // this function might be called twice
}
that.will = null // this function might be called twice
that._will = null

conn.removeAllListeners('error')
conn.on('error', nop)
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/index.js
Expand Up @@ -48,6 +48,7 @@ function handle (client, packet, done) {
handlePing(client, packet, done)
break
case 'disconnect':
// [MQTT-3.14.4-1]
client.disconnected = true
client.conn.end()
return
Expand Down
17 changes: 16 additions & 1 deletion test/will.js
Expand Up @@ -3,9 +3,9 @@
var test = require('tape').test
var memory = require('aedes-persistence')
var helper = require('./helper')
var aedes = require('../')
var setup = helper.setup
var connect = helper.connect
var aedes = require('../')

function willConnect (s, opts, connected) {
opts = opts || {}
Expand Down Expand Up @@ -297,3 +297,18 @@ test('does not deliver will if keepalive is triggered during authentication', fu

willConnect(setup(broker), opts)
})

// [MQTT-3.14.4-1]
test('does not deliver will when client sends a DISCONNECT', function (t) {
var broker = aedes()
var s = willConnect(setup(broker))

s.inStream.end({
cmd: 'disconnect'
})

s.broker.mq.on('mywill', function (packet, cb) {
t.fail(packet)
})
broker.on('closed', t.end.bind(t))
})

0 comments on commit f39b93f

Please sign in to comment.