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

Commit

Permalink
Merge pull request #132 from cfan8/master
Browse files Browse the repository at this point in the history
Fix a problem related to Issues #131 Getting duplicate messages using Mongodb as mosca backend.
  • Loading branch information
mcollina committed Sep 14, 2015
2 parents 0ab358d + cbb183f commit 5fb3ff3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo_ascoltatore.js
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
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);
});
});
});

0 comments on commit 5fb3ff3

Please sign in to comment.