Last active
August 29, 2015 14:22
-
-
Save maxired/61dffcfa7325bf438485 to your computer and use it in GitHub Desktop.
[pigato] test to show that W_DISCONNECT is not always sended by Worker
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
var zmq = require('zmq'); | |
var MDP = require('../lib/mdp'); | |
var PIGATO = require('../'); | |
var chai = require('chai'), | |
assert = chai.assert; | |
var uuid = require('node-uuid'); | |
var location = 'inproc://#'; | |
var bhost = location + uuid.v4(); | |
var worker, workerOpts, workerTopic = 'worker'; | |
describe('Worker', function() { | |
var mockBroker; | |
before(function() { | |
bhost = location + uuid.v4(); | |
worker = new PIGATO.Worker(bhost, workerTopic, workerOpts); | |
mockBroker = zmq.socket('router'); | |
mockBroker.bindSync(bhost); | |
}) | |
it('send Disconnect after stop is called when connected', function(done) { | |
var types = [MDP.W_READY, MDP.W_DISCONNECT]; | |
var typesIndex = 0; | |
mockBroker.on('message', function(a, b, c) { | |
console.log("receive message" , c.toString() ); | |
assert.equal(worker.conf.name, a.toString()); | |
assert.equal(MDP.WORKER, b.toString()); | |
assert.equal(types[typesIndex], c.toString()); | |
typesIndex++; | |
if (c.toString() == MDP.W_DISCONNECT) { | |
console.log("disconnect"); | |
done(); | |
return; | |
} | |
mockBroker.send([a, b, c]); | |
}); | |
worker.on('connect', function() { | |
console.log("will disconnect"); | |
worker.stop(); | |
}); | |
worker.start(); | |
}); | |
}); |
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
$./node_modules/.bin/mocha test/disconnect.js | |
child_process: customFds option is deprecated, use stdio instead. | |
Worker | |
receive message 1 | |
will disconnect | |
1) send Disconnect after stop is called when connected | |
0 passing (2s) | |
1 failing | |
1) Worker send Disconnect after stop is called when connected: | |
Error: timeout of 2000ms exceeded | |
at null.<anonymous> (/home/maxired/zone52-2/pigatomay/node_modules/mocha/lib/runnable.js:158:19) | |
at Timer.listOnTimeout (timers.js:110:15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment