Skip to content

Commit

Permalink
Merge pull request #30 from dpatekar/master
Browse files Browse the repository at this point in the history
fixed unsubscribe handler exception
  • Loading branch information
mcollina committed Feb 14, 2016
2 parents 4511c75 + 81328f1 commit e995424
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/handlers/unsubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ function actualUnsubscribe (client, packet, done) {
function doUnsubscribe (sub, done) {
var client = this.client
var broker = client.broker
var func = client.subscriptions[sub].func

delete client.subscriptions[sub]

broker.unsubscribe(
sub,
func,
done)
if (client.subscriptions[sub]) {
var func = client.subscriptions[sub].func
delete client.subscriptions[sub]
broker.unsubscribe(
sub,
func,
done)
} else {
done()
}
}

function completeUnsubscribe (err) {
Expand Down
23 changes: 23 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ test('unsubscribe', function (t) {
})
})

test('unsubscribe without subscribe', function (t) {
t.plan(1)

var s = noError(connect(setup()), t)

s.inStream.write({
cmd: 'unsubscribe',
messageId: 43,
unsubscriptions: ['hello']
})

s.outStream.once('data', function (packet) {
t.deepEqual(packet, {
cmd: 'unsuback',
messageId: 43,
dup: false,
length: 2,
qos: 0,
retain: false
}, 'packet matches')
})
})

test('unsubscribe on disconnect', function (t) {
var s = noError(connect(setup()), t)

Expand Down

0 comments on commit e995424

Please sign in to comment.