Skip to content

Commit

Permalink
Added a proper catch block for handling errors (#385)
Browse files Browse the repository at this point in the history
* Added a proper catch block for handling errors

* Promisify setImmediate

* Remove then()
  • Loading branch information
gnought committed Jan 31, 2020
1 parent 3e0af1f commit 0204c8f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/connect.js
Expand Up @@ -12,6 +12,7 @@ var mqtt = require('mqtt')
var mqttPacket = require('mqtt-packet')
var net = require('net')
var proxyProtocol = require('proxy-protocol-js')
var util = require('util')

;[{ ver: 3, id: 'MQIsdp' }, { ver: 4, id: 'MQTT' }].forEach(function (ele) {
test('connect and connack (minimal)', function (t) {
Expand Down Expand Up @@ -348,18 +349,18 @@ test('reject second CONNECT Packet sent while first CONNECT still in preConnect
await delay(ms)
s.inStream.write(msg)
}
const immediate = util.promisify(setImmediate)

(async () => {
try {
await Promise.all([msg(s, 100, packet1), msg(s, 200, packet2)])
setImmediate(() => {
broker.close()
t.end()
})
} catch (error) {
;(async () => {
await Promise.all([msg(s, 100, packet1), msg(s, 200, packet2)])
await immediate()
broker.close()
t.end()
})().catch(
(error) => {
t.fail(error)
}
})()
)
})

// [MQTT-3.1.2-1], Guarded in mqtt-packet
Expand Down

0 comments on commit 0204c8f

Please sign in to comment.