Skip to content

Commit

Permalink
fix: add test for new reconnectOnConnackError option
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabeler-lee-6rs committed Oct 16, 2024
1 parent abc335f commit 6f207c7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3335,6 +3335,41 @@ export default function abstractTest(server, config, ports) {
})
})

it('should reconnect on connack error if requested', function _test(t, done) {
let connackErrors = 0
const rcNotAuthorized = 135
const server2 = serverBuilder(config.protocol, (serverClient) => {
serverClient.on('connect', () => {
const rc = connackErrors === 0 ? rcNotAuthorized : 0
const connack =
version === 5 ? { reasonCode: rc } : { returnCode: rc }
serverClient.connack(connack)
})
})
server2.listen(ports.PORTAND50, () => {
const client = connect({
host: 'localhost',
port: ports.PORTAND50,
reconnectPeriod: 10,
reconnectOnConnackError: true,
})
.on('error', (err) => {
assert.instanceOf(err, ErrorWithReasonCode)
assert.equal(
(err as ErrorWithReasonCode).code,
rcNotAuthorized,
)
assert.equal(connackErrors, 0)
connackErrors++
})
.on('connect', () => {
assert.equal(connackErrors, 1)
client.end(true, done)
server2.close()
})
})
})

it(
'should resend in-flight QoS 1 publish messages from the client',
{
Expand Down

0 comments on commit 6f207c7

Please sign in to comment.