Skip to content

Commit

Permalink
Merge pull request #170 from cordovapolymer/master
Browse files Browse the repository at this point in the history
test for #158
  • Loading branch information
mcollina authored Nov 14, 2017
2 parents 4b0f0b8 + 3279198 commit c0da871
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/handlers/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function storeSubscriptions (sub, done) {
return done(null, sub)
}

if (client.clean) {
return done(null, sub)
}

perst.addSubscriptions(client, packet.subscriptions, function (err) {
done(err, sub)
})
Expand Down
32 changes: 32 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,38 @@ test('restore QoS 0 subscriptions not clean', function (t) {
})
})

test('do not restore QoS 0 subscriptions when clean', function (t) {
var broker = aedes()
var publisher
var subscriber = connect(setup(broker), { clean: true, clientId: 'abcde' })

subscribe(t, subscriber, 'hello', 0, function () {
subscriber.inStream.end()
t.equal(subscriber.broker.persistence._subscriptions.size, 0, 'no previous subscriptions restored')

publisher = connect(setup(broker))

subscriber = connect(setup(broker), { clean: true, clientId: 'abcde' }, function (connect) {
t.equal(connect.sessionPresent, false, 'session present is set to false')
publisher.inStream.write({
cmd: 'publish',
topic: 'hello',
payload: 'world',
qos: 0
})
})

subscriber.outStream.once('data', function (packet) {
t.fail('packet received')
t.end()
})
eos(subscriber.conn, function () {
t.equal(subscriber.broker.connectedClients, 0, 'no connected clients')
t.end()
})
})
})

test('double sub does not double deliver', function (t) {
var s = connect(setup())
var expected = {
Expand Down

0 comments on commit c0da871

Please sign in to comment.