From 6f207c77768880534b9f03d401ba80ad18a76a6c Mon Sep 17 00:00:00 2001 From: Matthew Gabeler-Lee Date: Wed, 16 Oct 2024 11:19:19 -0400 Subject: [PATCH] fix: add test for new reconnectOnConnackError option --- test/abstract_client.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/abstract_client.ts b/test/abstract_client.ts index df468b69c..f397216f6 100644 --- a/test/abstract_client.ts +++ b/test/abstract_client.ts @@ -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', {