Skip to content

Commit

Permalink
Merge 5d35282 into e2d64b2
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Aug 11, 2019
2 parents e2d64b2 + 5d35282 commit 8a54389
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/qos1.js
@@ -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
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()
})
})
})

0 comments on commit 8a54389

Please sign in to comment.