Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Also persist QoS 0 subscriptions when clean flag false #694

Merged
merged 3 commits into from
Oct 30, 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
7 changes: 3 additions & 4 deletions lib/persistence/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,10 @@ LevelUpPersistence.prototype.storeSubscriptions = function(client, done) {
var now = Date.now();

if (!client.clean) {
// Issue #693
Object.keys(client.subscriptions).forEach(function(key) {
if (client.subscriptions[key].qos > 0) {
subscriptions[key] = client.subscriptions[key];
subscriptions[key].ttl = that.options.ttl.subscriptions + now;
}
subscriptions[key] = client.subscriptions[key];
subscriptions[key].ttl = that.options.ttl.subscriptions + now;
});
this._clientSubscriptions.put(client.id, subscriptions, done);
Object.keys(subscriptions).forEach(function(key) {
Expand Down
8 changes: 5 additions & 3 deletions lib/persistence/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ MongoPersistence.prototype.storeSubscriptions = function(client, done) {
var that = this;

if (!client.clean) {
subscriptions = Object.keys(client.subscriptions).filter(function(key) {
return client.subscriptions[key].qos > 0;
});
// Issue #693
// subscriptions = Object.keys(client.subscriptions).filter(function(key) {
// return client.subscriptions[key].qos > 0;
// });
subscriptions = Object.keys(client.subscriptions);

steed.each(subscriptions, function(key, cb) {
that._subscriptions.findAndModify({
Expand Down
5 changes: 2 additions & 3 deletions lib/persistence/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ RedisPersistence.prototype.storeSubscriptions = function(client, cb) {
var that = this;
var subscriptions = {};

// Issue #693
Object.keys(client.subscriptions).forEach(function(key) {
if (client.subscriptions[key].qos > 0) {
subscriptions[key] = client.subscriptions[key];
}
subscriptions[key] = client.subscriptions[key];
});

this._client.get(clientSubKey, function(err, currentSubs){
Expand Down
4 changes: 2 additions & 2 deletions test/persistence/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ module.exports = function(create, buildOpts) {
});
});

it("should not store a QoS 0 subscription", function(done) {
it("should store a QoS 0 subscription", function(done) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please check/add a test that we are not enqueuing QoS 0 packets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me what you mean? You already have test for QoS 0 packages

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forget my comment :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eeeee... what comment???? ;)

var instance = this.instance;
var client = {
id: "my client id - 42",
Expand All @@ -573,7 +573,7 @@ module.exports = function(create, buildOpts) {

instance.storeSubscriptions(client, function() {
instance.lookupSubscriptions(client, function(err, results) {
expect(results).to.eql({});
expect(results).to.eql(client.subscriptions);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/persistence/mongo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("mosca.persistence.Mongo", function() {
var packet = {
topic: "hello/42",
qos: 0,
payload: 'someStringToTest', // not a buffer
payload: 'someStringToTest', // not a Buffer
messageId: 42
};

Expand Down