Skip to content

Commit

Permalink
fix: return error in pubrec (#512)
Browse files Browse the repository at this point in the history
* fix: return error in pubrec

* test pubrec
  • Loading branch information
robertsLando committed Jun 24, 2020
1 parent 09fc0ce commit 7aaa886
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/handlers/pubrec.js
Expand Up @@ -20,12 +20,10 @@ function handlePubrec (client, packet, done) {

function reply (err) {
if (err) {
// TODO is this ok?
client._onError(err)
return
done(err)
} else {
write(client, pubrel, done)
}

write(client, pubrel, done)
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/qos2.js
Expand Up @@ -143,6 +143,23 @@ test('publish QoS 2 throws error on write', function (t) {
})
})

test('pubrec handler calls done when outgoingUpdate fails (clean=false)', function (t) {
t.plan(1)

const s = connect(setup(), { clean: false })
t.tearDown(s.broker.close.bind(s.broker))

var handle = require('../lib/handlers/pubrec.js')

s.broker.persistence.outgoingUpdate = function (client, pubrel, done) {
done(Error('throws error'))
}

handle(s.client, { messageId: 42 }, function done () {
t.pass('calls done on error')
})
})

test('client.publish with clean=true subscribption QoS 2', function (t) {
t.plan(8)

Expand Down

0 comments on commit 7aaa886

Please sign in to comment.