From 7ec5330df4cd960e305a3497c2b4f987da6c6b6a Mon Sep 17 00:00:00 2001 From: fb55 Date: Wed, 2 Apr 2014 14:04:02 +0200 Subject: [PATCH] added test case for Queue#changes --- test/tap/cqs.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/tap/cqs.js b/test/tap/cqs.js index 4e9954c..56d4b10 100644 --- a/test/tap/cqs.js +++ b/test/tap/cqs.js @@ -532,3 +532,54 @@ test('Receive conflict', function(t) { } }) }) + +test('Follow changes', function(t) { + var changes = state.foo.changes() + + var unexpectedMessage = function() { + throw new Error('unexpected message') + } + + var receiveChange = function() { + changes.once('message', function(msg) { + t.equal(msg.Body, 'msg2') + msg.del(function(er) { + if(er) throw er; + changes.stop(); + t.end() + }) + }) + changes.removeListener('message', unexpectedMessage); + changes.resume(); + } + + var testPaused = function() { + changes.pause() + + state.foo.send('msg2', function(er) { + if(er) throw er; + + setTimeout(receiveChange, 100); + }) + } + + changes.once('message', function(msg) { + t.equal(msg.Body, 'msg1') + + changes.on('message', unexpectedMessage) + + msg.del(function(er) { + if(er) throw er; + + //should not receive messages from other queues + state.bar.send('noMsg', function(er){ + if(er) throw er; + testPaused(); + }) + }) + }) + + state.foo.send('msg1', function(er) { + if(er) throw er; + }) +})