Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
/*
2
* simple-test.js: Simple tests for using Monitor instances.
3
*
4
* (C) 2010 Nodejitsu Inc.
5
* MIT LICENCE
6
*
7
*/
8
9
var assert = require('assert'),
10
path = require('path'),
11
vows = require('vows'),
12
fmonitor = require('../../lib'),
13
macros = require('../helpers/macros');
14
15
var examplesDir = path.join(__dirname, '..', '..', 'examples');
16
17
vows.describe('forever-monitor/monitor/simple').addBatch({
18
"When using forever-monitor": {
19
"an instance of Monitor with valid options": {
20
topic: new (fmonitor.Monitor)(path.join(examplesDir, 'server.js'), {
21
max: 10,
22
silent: true,
23
options: ['-p', 8090]
24
}),
25
"should have correct properties set": function (child) {
26
assert.isArray(child.args);
27
assert.equal(child.max, 10);
28
assert.isTrue(child.silent);
29
assert.isFunction(child.start);
30
assert.isObject(child.data);
31
assert.isFunction(child.stop);
32
},
33
"calling the restart() method in less than `minUptime`": {
34
topic: function (child) {
35
var that = this;
36
child.once('start', function () {
37
child.once('restart', that.callback.bind(this, null));
38
child.restart();
39
});
40
child.start();
41
},
42
"should restart the child process": function (_, child, data) {
43
assert.isObject(data);
44
child.kill(true);
45
}
46
}
47
},
48
"running error-on-timer sample three times": macros.assertTimes(
49
path.join(examplesDir, 'error-on-timer.js'),
50
3,
51
{
52
minUptime: 200,
53
silent: true,
54
outFile: 'test/fixtures/stdout.log',
55
errFile: 'test/fixtures/stderr.log',
56
options: []
57
}
58
),
59
"running error-on-timer sample once": macros.assertTimes(
60
path.join(examplesDir, 'error-on-timer.js'),
61
1,
62
{
63
minUptime: 200,
64
silent: true,
65
outFile: 'test/fixtures/stdout.log',
66
errFile: 'test/fixtures/stderr.log',
67
options: []
68
}
69
),
70
"non-node usage with a perl one-liner": {
71
topic: function () {
72
var child = fmonitor.start([ 'perl', '-le', 'print "moo"' ], {
73
max: 1,
74
silent: true,
75
});
76
child.on('stdout', this.callback.bind({}, null));
77
},
78
"should get back moo": function (err, buf) {
79
assert.equal(buf.toString(), 'moo\n');
80
}
81
},
82
"attempting to start a script that doesn't exist": {
83
topic: function () {
84
var child = fmonitor.start('invalid-path.js', {
85
max: 1,
86
silent: true
87
});
88
child.on('error', this.callback.bind({}, null));
89
},
90
"should throw an error about the invalid file": function (err) {
91
assert.isNotNull(err);
92
assert.isTrue(err.message.indexOf('does not exist') !== -1);
93
}
94
}
95
}
96
}).export(module);
97
98