diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-04-04 01:00:59 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-04-04 01:00:59 -0700 |
| commit | c7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 (patch) | |
| tree | 8546df448afef40d3814d2581f4dacff7cebb87f /node_modules/forever/test/worker/simple-test.js | |
Diffstat (limited to 'node_modules/forever/test/worker/simple-test.js')
| -rw-r--r-- | node_modules/forever/test/worker/simple-test.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/node_modules/forever/test/worker/simple-test.js b/node_modules/forever/test/worker/simple-test.js new file mode 100644 index 0000000..26c4fb1 --- /dev/null +++ b/node_modules/forever/test/worker/simple-test.js @@ -0,0 +1,73 @@ +var path = require('path'), + assert = require('assert'), + vows = require('vows'), + nssocket = require('nssocket'), + macros = require('../helpers/macros'), + MonitorMock = require('../helpers/mocks/monitor').MonitorMock; + +var SOCKET_PATH = path.join(__dirname, '..', 'fixtures'); + +vows.describe('forever/worker/simple').addBatch({ + 'When using forever worker': { + 'and starting it and pinging it': macros.assertWorkerConnected({ + monitor: new MonitorMock(), + sockPath: SOCKET_PATH + }, { + 'and respond to pings': { + topic: function (reader) { + reader.send(['ping']); + reader.data(['pong'], this.callback); + }, + 'with `pong`': function () {} + }, + 'and when queried for data': { + topic: function (reader, _, options) { + var self = this; + + reader.send(['data']); + reader.data(['data'], function (data) { + self.callback(null, { data: data, monitor: options.monitor }); + }); + }, + 'it should respond with data': function (obj) { + assert.isObject(obj.data); + assert.deepEqual(obj.data, obj.monitor.data); + } + }, + 'and when asked to kill the process': { + topic: function (reader, _, options) { + var self = this; + + options.monitor.running = true; + reader.send(['stop']); + reader.data(['stop', 'ok'], function () { + self.callback(null, options.monitor); + }); + }, + 'it should kill the process': function (monitor) { + assert.isFalse(monitor.running); + } + }, + 'and when quickly sending data and disconnecting': { + topic: function(reader) { + var self = this; + + // Need to connect second reader, otherwise it breaks the other + // tests as the reader is shared with them. + var reader2 = new nssocket.NsSocket(); + reader2.connect(reader.host, function() { + reader2.send(['data']); + reader2.destroy(); + + setTimeout(self.callback, 100); + }); + }, + 'it should not crash the worker': function(worker) { + // no asserition, everything is good if the test does not cause + // a worker crash. + } + } + }) + } +}).export(module); + |
