From bc961a401d912c4eaf8fe0733c095622506e0324 Mon Sep 17 00:00:00 2001 From: Gnought <1684105+gnought@users.noreply.github.com> Date: Tue, 6 Apr 2021 14:32:13 +0800 Subject: [PATCH] chore: enhance not-blocking test for new MQTT.js behaviour (#608) --- test/not-blocking.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/not-blocking.js b/test/not-blocking.js index 63231461..7d428c89 100644 --- a/test/not-blocking.js +++ b/test/not-blocking.js @@ -7,12 +7,13 @@ const net = require('net') const Faketimers = require('@sinonjs/fake-timers') const aedes = require('../') -test('connect 200 concurrent clients', function (t) { +test('connect 500 concurrent clients', function (t) { t.plan(3) + const evt = new EventEmitter() const broker = aedes() const server = net.createServer(broker.handle) - const total = 200 + const total = 500 server.listen(0, function (err) { t.error(err, 'no error') @@ -27,25 +28,31 @@ test('connect 200 concurrent clients', function (t) { clock.setTimeout(function () { t.equal(clients.length, total) t.equal(connected, total) - for (let i = 0; i < clients.length; i++) { - clients[i].end() + while (clients.length) { + clients.shift().end() } - broker.close() - server.close() }, total) + evt.on('finish', function () { + if (clients.length === 0) { + broker.close() + server.close() + } + }) + for (let i = 0; i < total; i++) { clients[i] = mqtt.connect({ port: port, - keepalive: 0 + keepalive: 0, + reconnectPeriod: 100 }).on('connect', function () { connected++ if ((connected % (total / 10)) === 0) { console.log('connected', connected) } clock.tick(1) - }).on('error', function () { - clock.tick(1) + }).on('close', function () { + evt.emit('finish') }) } })