forked from postwait/node-amqp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |