Skip to content

Commit

Permalink
Fix a problem related to moscajs#131
Browse files Browse the repository at this point in the history
  • Loading branch information
cfan8 committed Sep 9, 2015
1 parent 0ab358d commit cbb183f
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
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);
});
});
});

0 comments on commit cbb183f

Please sign in to comment.