Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Logging poll stopping

  • Loading branch information...
commit 7b83a3ac2ec3d9b9fdeef464d073ed7cde90afa9 1 parent b12fee8
@christav christav authored
View
12 lib/sbstore.js
@@ -99,10 +99,13 @@ ServiceBusStore.prototype.unsubscribe = function (name, consumer) {
this.emit('unsubscribe', name, consumer);
}
-ServiceBusStore.prototype.destroy = function () {
- Store.prototype.destroy.call(this);
- this.sb.stop();
- this.subscribers = {};
+ServiceBusStore.prototype.destroy = function (stoppedCallback) {
+ var self = this;
+ this.sb.stop(function () {
+ io.Store.prototype.destroy.call(self);
+ self.subscribers = {};
+ stoppedCallback && stoppedCallback();
+ });
}
ServiceBusStore.prototype.receiveMessage = function (sourceNodeId, name, args) {
@@ -135,6 +138,7 @@ ServiceBusStore.prototype.createServiceBusConnector = function createServiceBusC
topic: options.topic,
subscription: options.subscription,
serviceBusService: this.serviceBusService,
+ numReceives: options.numReceives,
logger: this.log
};
View
1  lib/servicebusconnector.js
@@ -63,6 +63,7 @@ ServiceBusConnector.prototype.start = function () {
pollSb();
} else {
--self.receivesRunning;
+ self.log && self.log.info('Service Bus poll stopped', 'num:' + self.receivesRunning);
if(self.receivesRunning === 0) {
self.stopCallback && self.stopCallback(null);
}
View
25 test/logging-tests.js
@@ -24,10 +24,15 @@ describe('logging', function () {
var store;
var logger;
var serviceBusService;
+ var recvFuncs;
beforeEach(function () {
+ recvFuncs = [];
+
serviceBusService = {
- receiveSubscriptionMessage: sinon.spy(),
+ receiveSubscriptionMessage: function (topic, sub, callback) {
+ recvFuncs.push(callback);
+ },
sendTopicMessage: sinon.spy(),
withFilter: function (filter) { return this; },
host: 'testnamespace.servicebus.example'
@@ -61,4 +66,22 @@ describe('logging', function () {
logger.info.calledWith('Service Bus poll started', 'num:0').should.be.true;
logger.info.calledWith('Service Bus poll started', 'num:1').should.be.true;
});
+
+ it('should log when polling stops', function (done) {
+ store.destroy(function () {
+ logger.info.calledWith('Service Bus poll stopped', 'num:1').should.be.true;
+ logger.info.calledWith('Service Bus poll stopped', 'num:0').should.be.true;
+ done();
+ });
+
+ // trigger the receive poll callbacks so they exit
+ recvNothing();
+ recvNothing();
+ });
+
+ // Helpers for sending messages
+ function recvNothing() {
+ var recvFunc = recvFuncs.shift();
+ recvFunc('No messages to receive');
+ }
});
Please sign in to comment.
Something went wrong with that request. Please try again.