Skip to content

Commit

Permalink
fix(test): close open connections (#1911)
Browse files Browse the repository at this point in the history
* 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 <daniel.sorridi@gmail.com>
  • Loading branch information
MaximoLiberata and robertsLando committed Aug 1, 2024
1 parent 2da3b34 commit 053a7be
Show file tree
Hide file tree
Showing 4 changed files with 406 additions and 67 deletions.
5 changes: 4 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ export type OnMessageCallback = (
export type OnPacketCallback = (packet: Packet) => void
export type OnCloseCallback = () => void
export type OnErrorCallback = (error: Error | ErrorWithReasonCode) => void
export type PacketCallback = (error?: Error, packet?: Packet) => any
export type PacketCallback = (
error?: Error | ErrorWithReasonCode,
packet?: Packet,
) => any
export type CloseCallback = (error?: Error) => void

export interface MqttClientEventCallbacks {
Expand Down
14 changes: 9 additions & 5 deletions src/lib/handlers/ack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Other Socket Errors: EADDRINUSE, ECONNRESET, ENOTFOUND, ETIMEDOUT.

import { PacketHandler } from '../shared'
import { PacketHandler, ErrorWithReasonCode } from '../shared'

export const ReasonCodes = {
0: '',
Expand Down Expand Up @@ -82,8 +82,10 @@ const handleAck: PacketHandler = (client, packet) => {
const pubackRC = packet.reasonCode
// Callback - we're done
if (pubackRC && pubackRC > 0 && pubackRC !== 16) {
err = new Error(`Publish error: ${ReasonCodes[pubackRC]}`)
err.code = pubackRC
err = new ErrorWithReasonCode(
`Publish error: ${ReasonCodes[pubackRC]}`,
pubackRC,
)
client['_removeOutgoingAndStoreMessage'](messageId, () => {
cb(err, packet)
})
Expand All @@ -102,8 +104,10 @@ const handleAck: PacketHandler = (client, packet) => {
const pubrecRC = packet.reasonCode

if (pubrecRC && pubrecRC > 0 && pubrecRC !== 16) {
err = new Error(`Publish error: ${ReasonCodes[pubrecRC]}`)
err.code = pubrecRC
err = new ErrorWithReasonCode(
`Publish error: ${ReasonCodes[pubrecRC]}`,
pubrecRC,
)
client['_removeOutgoingAndStoreMessage'](messageId, () => {
cb(err, packet)
})
Expand Down
Loading

0 comments on commit 053a7be

Please sign in to comment.