Skip to content

Commit

Permalink
More reliable test in 'subscribe and publish QoS 1 in parallel' (#262)
Browse files Browse the repository at this point in the history
* More reliable test in 'subscribe and publish QoS 1 in parallel'
In a parallel testing, publish and suback may not arrive in order in different machines.

* Elimiate count variable
  • Loading branch information
gnought authored and mcollina committed Jul 17, 2019
1 parent ec11c39 commit 565d710
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions test/qos1.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ test('not clean and retain messages with QoS 1', function (t) {
})

test('subscribe and publish QoS 1 in parallel', function (t) {
t.plan(5)

var broker = aedes()
var s = connect(setup(broker))
var expected = {
Expand All @@ -695,19 +697,19 @@ test('subscribe and publish QoS 1 in parallel', function (t) {
s.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'puback')
t.equal(packet.messageId, 42, 'messageId must match')
s.outStream.once('data', function (packet) {
s.inStream.write({
cmd: 'puback',
messageId: packet.messageId
})
delete packet.messageId
t.deepEqual(packet, expected, 'packet must match')
s.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'suback')
s.outStream.on('data', function (packet) {
if (packet.cmd === 'suback') {
t.deepEqual(packet.granted, [1])
t.equal(packet.messageId, 24)
t.end()
})
}
if (packet.cmd === 'publish') {
s.inStream.write({
cmd: 'puback',
messageId: packet.messageId
})
delete packet.messageId
t.deepEqual(packet, expected, 'packet must match')
}
})
})

Expand Down

0 comments on commit 565d710

Please sign in to comment.