Skip to content

Commit

Permalink
[test] add aother test and some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrugzz committed Jan 5, 2015
1 parent 9bf120b commit 2cae062
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
4 changes: 2 additions & 2 deletions socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ RepSocket.prototype._consume = function (msg) {
this.emit('message', payload, reply);

function reply(err, data) {
debug('rep socket reply being executed');
debug('rep socket reply being executed %j', arguments);
if (err) {
//
// Remark: This is something weird TBH as it shouldn't happen
Expand Down Expand Up @@ -234,7 +234,7 @@ ReqSocket.prototype._canMaybeSend = function () {
};

ReqSocket.prototype._consume = function (msg) {
if (msg === null) return;
if (msg === null) return debug('Req socket msg received is null');
debug('Req socket received reply over ephemeral queue %s %j', this.replyTo, msg);
this.reply(msg);
this.channel.ack(msg);
Expand Down
73 changes: 70 additions & 3 deletions test/simple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ var assume = require('assume');
describe('Simple request/reply', function () {

it('should succeed', function (done) {

var rabbit = new Rabbit()
.on('ready', function () {
console.log('rabbit ready');
});

var req = rabbit.socket('REQ')
.on('error', console.error.bind(console))
.on('error', function (err) {
assume(err).does.not.exist();
done(err);
})
.on('ready', function () {
console.log('REQ socket ready');
})
.connect('made_up_queue')
.on('connect', function () {
console.log('REQ has connected');
})
.send({foo: 'bar'}, function (_, msg) {
.send({foo: 'bar'}, function (err, msg) {
assume(err).does.not.exist()
assume(msg).is.an('object');
assume(msg.reply).is.ok();
assume(msg.reply).equals('wooo');
Expand All @@ -28,6 +31,7 @@ describe('Simple request/reply', function () {

var rep = rabbit.socket('REP')
.on('error', function (err) {
assume(err).does.not.exist();
done(err);
})
.on('ready', function () {
Expand All @@ -39,7 +43,70 @@ describe('Simple request/reply', function () {
})
.on('message', function (msg, reply) {
assume(msg).is.an('object');
assume(msg.foo).is.ok();
assume(msg.foo).equals('bar');
reply(undefined, {reply: 'wooo'});
});
});

it('should handle concurrent messages with different connections', function (done) {
var count = 0;

function isDone() {
if (++count === 2) done();
}
var rabbit = new Rabbit()
.on('error', function (err) {
console.error(err);
console.dir(err.message);
done(err);
})

var otherRabbit = new Rabbit()
.on('error', function (err) {
console.error(err);
console.dir(err.message);
done(err);
});

var req = rabbit.socket('REQ')
.on('error', done)
.on('ready', function () {
console.log('REQ socket ready');
})
.connect('nnew_made_up_queue')
.on('connect', function () {
console.log('REQ has connected');
})
.send({foo: 'bar'}, function (err, msg) {
assume(msg).is.an('object');
assume(msg.reply).is.ok();
assume(msg.reply).equals('wooo');
isDone();
})
.send({foo: 'bar'}, function (err, msg) {
assume(msg).is.an('object');
assume(msg.reply).is.ok();
assume(msg.reply).equals('wooo');
isDone();
});

var rep = otherRabbit.socket('REP')
.on('error', function (err) {
console.dir(err);
console.dir(err.message);
done(err);
})
.on('ready', function () {
console.log('REP socket ready');
})
.connect('nnew_made_up_queue')
.on('connect', function () {
console.log('REP has connected');
})
.on('message', function (msg, reply) {
assume(reply).is.a('function');
assume(msg).is.an('object');
assume(msg.foo).is.ok();
assume(msg.foo).equals('bar');
reply(undefined, {reply: 'wooo'});
Expand Down

0 comments on commit 2cae062

Please sign in to comment.