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

Retain false when subscriber is active #130

Merged
merged 5 commits into from
Aug 19, 2017
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
1 change: 1 addition & 0 deletions aedes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function storeRetained (_, done) {
}

function emitPacket (_, done) {
this.packet.retain = false
this.broker.mq.emit(this.packet, done)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"aedes-packet": "^1.0.0",
"aedes-persistence": "^4.0.0",
"aedes-persistence": "^5.1.1",
"bulk-write-stream": "^1.0.0",
"end-of-stream": "^1.1.0",
"fastfall": "^1.0.0",
Expand Down
33 changes: 33 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
33 changes: 32 additions & 1 deletion test/qos1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down