Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests to proper handling of new socketErrors introducing in mqtt client v4 #593

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions test/not-blocking.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const { test } = require('tap')
const EventEmitter = require('events')
const mqtt = require('mqtt')
const net = require('net')
const Faketimers = require('@sinonjs/fake-timers')
Expand Down Expand Up @@ -53,6 +54,7 @@ test('connect 200 concurrent clients', function (t) {
test('do not block after a subscription', function (t) {
t.plan(3)

const evt = new EventEmitter()
const broker = aedes()
const server = net.createServer(broker.handle)
const total = 10000
Expand Down Expand Up @@ -97,10 +99,8 @@ test('do not block after a subscription', function (t) {
port: port,
keepalive: 0
}).on('error', function (err) {
if (err.code !== 'ECONNRESET') {
clock.clearTimeout(clockId)
t.fail(err)
}
clock.clearTimeout(clockId)
t.fail(err)
})

subscriber.subscribe('test', publish)
Expand All @@ -112,24 +112,33 @@ test('do not block after a subscription', function (t) {
received++
clock.tick(1)
})
subscriber.on('close', function () {
evt.emit('finish')
})
}

publisher.on('connect', startSubscriber)

function finish () {
subscriber.end()
publisher.end()
publisher.on('close', function () {
evt.emit('finish')
})
evt.on('finish', function () {
if (publisher.connected || subscriber.connected) { return }
broker.close()
server.close()
t.equal(total, sent, 'messages sent')
t.equal(total, received, 'messages received')
})
function finish () {
subscriber.end()
publisher.end()
}
})
})

test('do not block with overlapping subscription', function (t) {
t.plan(3)

const evt = new EventEmitter()
const broker = aedes({ concurrency: 15 })
const server = net.createServer(broker.handle)
const total = 10000
Expand Down Expand Up @@ -174,10 +183,8 @@ test('do not block with overlapping subscription', function (t) {
port: port,
keepalive: 0
}).on('error', function (err) {
if (err.code !== 'ECONNRESET') {
clock.clearTimeout(clockId)
t.fail(err)
}
clock.clearTimeout(clockId)
t.fail(err)
})

subscriber.subscribe('#', function () {
Expand All @@ -193,17 +200,25 @@ test('do not block with overlapping subscription', function (t) {
received++
clock.tick(1)
})
subscriber.on('close', function () {
evt.emit('finish')
})
}

publisher.on('connect', startSubscriber)

function finish () {
subscriber.end()
publisher.end()
publisher.on('close', function () {
evt.emit('finish')
})
evt.on('finish', function () {
if (publisher.connected || subscriber.connected) { return }
broker.close()
server.close()
t.equal(total, sent, 'messages sent')
t.equal(total, received, 'messages received')
})
function finish () {
subscriber.end()
publisher.end()
}
})
})