Skip to content

Commit

Permalink
chore: enhance not-blocking test for new MQTT.js behaviour (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought authored Apr 6, 2021
1 parent 2aa9009 commit bc961a4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test/not-blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
})
}
})
Expand Down

0 comments on commit bc961a4

Please sign in to comment.