Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
var path = require('path'),
2
assert = require('assert'),
3
vows = require('vows'),
4
nssocket = require('nssocket'),
5
macros = require('../helpers/macros'),
6
MonitorMock = require('../helpers/mocks/monitor').MonitorMock;
7
8
var SOCKET_PATH = path.join(__dirname, '..', 'fixtures');
9
10
vows.describe('forever/worker/simple').addBatch({
11
'When using forever worker': {
12
'and starting it and pinging it': macros.assertWorkerConnected({
13
monitor: new MonitorMock(),
14
sockPath: SOCKET_PATH
15
}, {
16
'and respond to pings': {
17
topic: function (reader) {
18
reader.send(['ping']);
19
reader.data(['pong'], this.callback);
20
},
21
'with `pong`': function () {}
22
},
23
'and when queried for data': {
24
topic: function (reader, _, options) {
25
var self = this;
26
27
reader.send(['data']);
28
reader.data(['data'], function (data) {
29
self.callback(null, { data: data, monitor: options.monitor });
30
});
31
},
32
'it should respond with data': function (obj) {
33
assert.isObject(obj.data);
34
assert.deepEqual(obj.data, obj.monitor.data);
35
}
36
},
37
'and when asked to kill the process': {
38
topic: function (reader, _, options) {
39
var self = this;
40
41
options.monitor.running = true;
42
reader.send(['stop']);
43
reader.data(['stop', 'ok'], function () {
44
self.callback(null, options.monitor);
45
});
46
},
47
'it should kill the process': function (monitor) {
48
assert.isFalse(monitor.running);
49
}
50
},
51
'and when quickly sending data and disconnecting': {
52
topic: function(reader) {
53
var self = this;
54
55
// Need to connect second reader, otherwise it breaks the other
56
// tests as the reader is shared with them.
57
var reader2 = new nssocket.NsSocket();
58
reader2.connect(reader.host, function() {
59
reader2.send(['data']);
60
reader2.destroy();
61
62
setTimeout(self.callback, 100);
63
});
64
},
65
'it should not crash the worker': function(worker) {
66
// no asserition, everything is good if the test does not cause
67
// a worker crash.
68
}
69
}
70
})
71
}
72
}).export(module);
73
74
75