Skip to content

Commit

Permalink
fix(multiple-receivers): register callback when attaching
Browse files Browse the repository at this point in the history
Bug missed in the promisification of createReceiver where callbacks
passed in with createReceiver during attachment were not retained.
  • Loading branch information
mbroadst committed Jun 16, 2015
1 parent ecc0723 commit 1a991b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/amqp_client.js
Expand Up @@ -440,6 +440,8 @@ AMQPClient.prototype.createReceiver = function(source, filter, cb) {

var linkName = source + '_RX';
if (this._attaching[linkName]) {
self._onReceipt[linkName].push(cb);

return new Promise(function(resolve, reject) {
var attachingListener = function(link) {
if (link.name === linkName) {
Expand Down
24 changes: 24 additions & 0 deletions test/integration/qpid/client.test.js
@@ -1,6 +1,7 @@
'use strict';
var AMQPClient = require('../../..').Client,
Message = require('../../../lib/types/message'),
Promise = require('bluebird'),
config = require('./config'),
expect = require('chai').expect;

Expand Down Expand Up @@ -36,6 +37,29 @@ describe('Client', function() {
});
});

it('should be able to create multiple receivers for same link', function(done) {
var receviedCount = 0;
var messageHandler = function(err, message) {
expect(message.body).to.equal('TESTMESSAGE');
receviedCount++;
if (receviedCount === 2) done();
};

test.client.connect(config.address)
.then(function() {
return Promise.all([
test.client.createReceiver(config.defaultLink, null, messageHandler),
test.client.createReceiver(config.defaultLink, null, messageHandler)
]);
})
.then(function() {
return test.client.send('TESTMESSAGE', config.defaultLink);
})
.catch(function(err) {
expect(err).to.not.exist;
});
});

describe('Messages', function() {
[
{
Expand Down

0 comments on commit 1a991b3

Please sign in to comment.