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

Enhance QoS tests & check if publish packets stored properly in persistence storage #292

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 19 additions & 3 deletions test/qos1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var concat = require('concat-stream')
var Buffer = require('safe-buffer').Buffer
var test = require('tape').test
var helper = require('./helper')
Expand Down Expand Up @@ -273,12 +274,15 @@ test('remove stored subscriptions if connected with clean=true', function (t) {
})

test('resend publish on non-clean reconnect QoS 1', function (t) {
t.plan(6)
t.plan(8)

var broker = aedes()
var publisher
var opts = { clean: false, clientId: 'abcde' }
var subscriber = connect(setup(broker), opts)
var subscriberClient = {
id: opts.clientId
}
var expected = {
cmd: 'publish',
topic: 'hello',
Expand All @@ -301,7 +305,13 @@ test('resend publish on non-clean reconnect QoS 1', function (t) {
qos: 1,
messageId: 42
})

publisher.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world world',
qos: 1,
messageId: 42
})
publisher.outStream.once('data', function (packet) {
t.equal(packet.cmd, 'puback')

Expand All @@ -315,7 +325,13 @@ test('resend publish on non-clean reconnect QoS 1', function (t) {
t.notEqual(packet.messageId, 42, 'messageId must differ')
delete packet.messageId
t.deepEqual(packet, expected, 'packet must match')
t.end()
setImmediate(() => {
var stream = broker.persistence.outgoingStream(subscriberClient)
stream.pipe(concat(function (list) {
t.equal(list.length, 1, 'should remain one item in queue')
t.deepEqual(list[0].payload, Buffer.from('world world'), 'packet must match')
}))
})
})
})
})
Expand Down
32 changes: 32 additions & 0 deletions test/qos2.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,35 @@ test('publish after disconnection', function (t) {
})
})
})

test('multiple publish and store one', function (t) {
t.plan(2)

var broker = aedes()
var sid = {
id: 'abcde'
}
var s = connect(setup(broker), { clientId: sid.id })
var toPublish = {
cmd: 'publish',
topic: 'hello',
payload: Buffer.from('world'),
qos: 2,
retain: false,
messageId: 42
}

var count = 5
while (--count) {
s.inStream.write(toPublish)
}
broker.on('closed', function () {
broker.persistence.incomingGetPacket(sid, toPublish, function (err, origPacket) {
delete origPacket.brokerId
delete origPacket.brokerCounter
t.deepEqual(origPacket, toPublish, 'packet must match')
t.error(err)
t.end()
})
})
})