Skip to content

Commit 053a7be

Browse files
fix(test): close open connections (#1911)
* fix: tets hang up * fix(test): close open connections * test: catch error * feat: move clean_method class to help * fix: hang tests * fix: lint style * fix: teardown helper functionality * docs: change examples according new changes --------- Co-authored-by: Daniel Lando <[email protected]>
1 parent 2da3b34 commit 053a7be

File tree

4 files changed

+406
-67
lines changed

4 files changed

+406
-67
lines changed

src/lib/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,10 @@ export type OnMessageCallback = (
385385
export type OnPacketCallback = (packet: Packet) => void
386386
export type OnCloseCallback = () => void
387387
export type OnErrorCallback = (error: Error | ErrorWithReasonCode) => void
388-
export type PacketCallback = (error?: Error, packet?: Packet) => any
388+
export type PacketCallback = (
389+
error?: Error | ErrorWithReasonCode,
390+
packet?: Packet,
391+
) => any
389392
export type CloseCallback = (error?: Error) => void
390393

391394
export interface MqttClientEventCallbacks {

src/lib/handlers/ack.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND, ETIMEDOUT.
22

3-
import { PacketHandler } from '../shared'
3+
import { PacketHandler, ErrorWithReasonCode } from '../shared'
44

55
export const ReasonCodes = {
66
0: '',
@@ -82,8 +82,10 @@ const handleAck: PacketHandler = (client, packet) => {
8282
const pubackRC = packet.reasonCode
8383
// Callback - we're done
8484
if (pubackRC && pubackRC > 0 && pubackRC !== 16) {
85-
err = new Error(`Publish error: ${ReasonCodes[pubackRC]}`)
86-
err.code = pubackRC
85+
err = new ErrorWithReasonCode(
86+
`Publish error: ${ReasonCodes[pubackRC]}`,
87+
pubackRC,
88+
)
8789
client['_removeOutgoingAndStoreMessage'](messageId, () => {
8890
cb(err, packet)
8991
})
@@ -102,8 +104,10 @@ const handleAck: PacketHandler = (client, packet) => {
102104
const pubrecRC = packet.reasonCode
103105

104106
if (pubrecRC && pubrecRC > 0 && pubrecRC !== 16) {
105-
err = new Error(`Publish error: ${ReasonCodes[pubrecRC]}`)
106-
err.code = pubrecRC
107+
err = new ErrorWithReasonCode(
108+
`Publish error: ${ReasonCodes[pubrecRC]}`,
109+
pubrecRC,
110+
)
107111
client['_removeOutgoingAndStoreMessage'](messageId, () => {
108112
cb(err, packet)
109113
})

0 commit comments

Comments
 (0)