Permalink
Browse files

Logging failure to send error

  • Loading branch information...
1 parent 38b1260 commit f5b1b275c29f0778b24b26dc311fd842faa223e5 @christav christav committed Mar 16, 2013
Showing with 22 additions and 12 deletions.
  1. +2 −1 lib/servicebusconnector.js
  2. +20 −1 test/logging-tests.js
  3. +0 −10 test/servicebusconnector-tests.js
@@ -90,7 +90,8 @@ ServiceBusConnector.prototype.send = function (name, args) {
var message = this.packMessage(name, args);
this.serviceBusSender.sendTopicMessage(this.topic, message, function (err) {
if (err) {
- self.emit('sberror', new Error('Failed to write to service bus on topic %s, err = %s', self.topic, util.inspect(err)));
+ self.log && self.log.error('Service Bus send to topic failed',
+ 'topic:' + self.topic, 'error:' + err.toString());
}
});
}
View
@@ -25,8 +25,10 @@ describe('logging', function () {
var logger;
var serviceBusService;
var recvFuncs;
+ var clock;
beforeEach(function () {
+ clock = sinon.useFakeTimers();
recvFuncs = [];
serviceBusService = {
@@ -51,10 +53,15 @@ describe('logging', function () {
subscription: 'testsubscription',
serviceBusService: serviceBusService,
numReceives: 2,
- logger: logger
+ logger: logger,
+ flushIntervalMS: 100
});
});
+ afterEach(function () {
+ clock.restore();
+ });
+
it('should log subscription info on creation', function () {
logger.info.calledWith('Service Bus Store created',
'host:' + serviceBusService.host,
@@ -137,6 +144,18 @@ describe('logging', function () {
'messageId:' + message.brokerProperties.MessageId).should.be.true;
});
+ it('should log failure to send', function () {
+ store.publish('aMessage', 1, 2, 3);
+ // message batcher flush
+ clock.tick(300);
+
+ var sendCallback = serviceBusService.sendTopicMessage.getCall(0).args[2];
+ sendCallback('Service Bus send failed');
+
+ logger.error.calledWith('Service Bus send to topic failed',
+ 'topic:testtopic', 'error:Service Bus send failed').should.be.true;
+ });
+
// Helpers for sending messages
function recvNothing() {
var recvFunc = recvFuncs.shift();
@@ -114,16 +114,6 @@ describe('Service Bus connection layer', function () {
sentMessage.body.should.equal('"hello"');
});
-
- it('should emit sberror event if service bus send fails', function () {
- var stub = sinon.stub().callsArgWith(2, new Error('Fake failure'));
- sb.sendTopicMessage = stub;
- var error = null;
- connector.on('sberror', function (err) { console.log('there was an error'); error = err; })
- connector.send('msg', 'hello', {seq: 6, next: 7});
-
- error.should.exist;
- });
});
describe('when receiving with one receive at a time', function () {

0 comments on commit f5b1b27

Please sign in to comment.