From 644ce713667ba2576000998e43e470401daf212a Mon Sep 17 00:00:00 2001 From: "gianluca.casagrande" Date: Tue, 9 Jan 2024 17:32:55 +0100 Subject: [PATCH] add clear closed clients test --- test/events.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/events.js b/test/events.js index 40191395..cd2137a1 100644 --- a/test/events.js +++ b/test/events.js @@ -221,3 +221,20 @@ test('Test backpressure aedes published function', function (t) { }) }) }) + +test('clear closed clients when the same clientId is managed by another broker', function (t) { + t.plan(1) + + const clientId = 'closed-client' + const broker = aedes() + + // simulate a closed client on the broker + broker.clients[clientId] = { closed: true } + + // simulate the creation of the same client on another broker of the cluster + broker.publish({ topic: '$SYS/anotherbroker/new/clients', payload: clientId }, () => { + t.equal(broker.clients[clientId], undefined) // check that the closed client was removed + }) + + t.teardown(broker.close.bind(broker)) +})