Skip to content

Commit

Permalink
Test for unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
squaremo committed Oct 18, 2011
1 parent 4638711 commit e6192b5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/test-unsubscribe.js
@@ -0,0 +1,27 @@
require('./harness');

var queueName = 'node-unsubscribe-test';
var counter = 0;

connection.on('ready', function() {
var ex = connection.exchange('');
var q = connection.queue(queueName, {autoDelete: false}, function() {
ex.publish(queueName, {"msg": 'Message1'});
var defr = q.subscribe(function() { counter += 1; });
defr.addCallback(function(ok) {
// NB there is a race here, since the publish above and this
// unsubscribe are sent over different channels.
var defr2 = q.unsubscribe(ok.consumerTag);
defr2.addCallback(function() {
connection.publish(queueName, {"msg": 'Message2'});
// alas I cannot think of a way to synchronise on the queue
setTimeout(function() { q.destroy().addCallback(function() {
connection.end(); })}, 500);
});
});
});
});

process.addListener('exit', function() {
assert.equal(1, counter);
});

0 comments on commit e6192b5

Please sign in to comment.