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

Fix a problem related to Issues #131 Getting duplicate messages using Mongodb as mosca backend. #132

Merged
merged 1 commit into from
Sep 14, 2015
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
2 changes: 1 addition & 1 deletion lib/mongo_ascoltatore.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ MongoAscoltatore.prototype._more = function(latest) {

debug('calling the subscriber callback');

latest = doc._id;
latest = latest > doc._id ? latest: doc._id;
that._lastSuccessfulHandling = latest;

if (!that._closed) {
Expand Down
26 changes: 26 additions & 0 deletions test/mongo_ascoltatore_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,30 @@ describeAscoltatore("mongo", function() {
setTimeout(done, 3000);
});
});

it("should not duplicate messages when sending messages sequentially", function(done) {
this.timeout(5000);

var that = this;
var called = 0;
that.instance.sub("hello", function(topic, value) {
called++;
expect(called).to.be.lessThan(7);
expect(value).to.eql(new Buffer("42"));
}, function() {
setTimeout(function(){
that.instance.pub("hello", new Buffer("42"));
that.instance.pub("hello", new Buffer("42"));
setTimeout(function(){
that.instance.pub("hello", new Buffer("42"));
that.instance.pub("hello", new Buffer("42"));
setTimeout(function(){
that.instance.pub("hello", new Buffer("42"));
that.instance.pub("hello", new Buffer("42"));
},100);
},100);
},100);
setTimeout(done, 3000);
});
});
});