simple-test.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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();
self.callback();
});
},
'it should not crash the worker': function(worker) {
// no asserition, everything is good if the test does not cause
// a worker crash.
}
}
})
}
}).export(module);