diff --git a/aedes.js b/aedes.js index 364f1d4a..14b31421 100644 --- a/aedes.js +++ b/aedes.js @@ -146,6 +146,7 @@ function storeRetained (_, done) { } function emitPacket (_, done) { + this.packet.retain = false this.broker.mq.emit(this.packet, done) } diff --git a/test/basic.js b/test/basic.js index 00b1dbe0..d816c12e 100644 --- a/test/basic.js +++ b/test/basic.js @@ -157,6 +157,39 @@ test('unsubscribe', function (t) { }) }) +test('live retain packets', function (t) { + t.plan(5) + var expected = { + cmd: 'publish', + topic: 'hello', + payload: Buffer.from('world'), + retain: false, + dup: false, + length: 12, + qos: 0 + } + + var s = noError(connect(setup()), t) + + subscribe(t, s, 'hello', 0, function () { + s.outStream.on('data', function (packet) { + t.deepEqual(packet, expected) + }) + + s.broker.publish({ + cmd: 'publish', + topic: 'hello', + payload: Buffer.from('world'), + retain: true, + dup: false, + length: 12, + qos: 0 + }, function () { + t.pass('publish finished') + }) + }) +}) + test('unsubscribe without subscribe', function (t) { t.plan(1) diff --git a/test/qos1.js b/test/qos1.js index 9a29e334..9307a512 100644 --- a/test/qos1.js +++ b/test/qos1.js @@ -416,6 +416,37 @@ test('deliver QoS 1 retained messages', function (t) { }) }) +test('deliver QoS 1 retained messages', function (t) { + var broker = aedes() + var publisher = connect(setup(broker)) + var subscriber = connect(setup(broker)) + var expected = { + cmd: 'publish', + topic: 'hello', + payload: Buffer.from('world'), + qos: 1, + dup: false, + length: 14, + retain: false + } + + subscribe(t, subscriber, 'hello', 1, function () { + subscriber.outStream.once('data', function (packet) { + delete packet.messageId + t.deepEqual(packet, expected, 'packet must match') + t.end() + }) + publisher.inStream.write({ + cmd: 'publish', + topic: 'hello', + payload: 'world', + qos: 1, + messageId: 42, + retain: true + }) + }) +}) + test('deliver QoS 0 retained message with QoS 1 subscription', function (t) { var broker = aedes() var publisher = connect(setup(broker)) @@ -448,7 +479,7 @@ test('deliver QoS 0 retained message with QoS 1 subscription', function (t) { publisher.inStream.write({ cmd: 'publish', topic: 'hello', - payload: 'world', + payload: Buffer.from('world'), qos: 0, messageId: 42, retain: true