Skip to content

Commit

Permalink
added test case for Queue#changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Apr 2, 2014
1 parent 611b5ed commit 7ec5330
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/tap/cqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
})

0 comments on commit 7ec5330

Please sign in to comment.