-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
134 lines (120 loc) · 3.02 KB
/
test.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict'
let pm2 = require('.')
let tm = 0
function runTest(what, after, test) {
tm += after
setTimeout(() => {
console.log(`\n***** ${what} *****`)
test()
}, tm)
}
runTest("These should fail for various reasons",
100,
() => {
pm2.start()
pm2.start({
name: 'fails',
}, (err) => {
console.error('fails:',err)
})
pm2.start({
name: 'fail1',
cwd: './tester',
})
pm2.start({
name: 'fail2',
script: './tester',
})
})
runTest("Start a NodeJS process",
1000,
() => {
pm2.start({
name: 'nodejs-process',
cwd: './tester/with-new/process1'
})
})
runTest("Start a Python process (output in log file)",
1000,
() => {
pm2.start({
name: 'python-process',
script: './tester/with-new/process1/process2/serve.py',
log: 'process2.log',
}, (err, pid) => {
if(err && pid) console.error(err, pid)
else if(err) console.error(err)
else if(pid) console.log(`PID: ${pid}`)
})
})
runTest("Stop the Python process",
2000,
() => {
pm2.stop('python-process', (err) => {
if(err) console.error(err)
})
})
runTest("Restart the NodeJS process",
1000, () => pm2.restart('nodejs-process'))
runTest("Stop the Python process again (will fail)",
1000,
() => {
pm2.stop('python-process', (err) => {
if(err) console.error(err)
})
})
runTest("Stop the NodeJS process completely",
1000,
() => {
pm2.stop('nodejs-process', (err) => {
if(err) console.error(err)
})
})
runTest("Start another Python process",
1000,
() => {
pm2.start({
name: 'python-process',
script: './tester/with-new/process1/process2/serve.py',
})
})
runTest("Try killing this [100,1000,30000]/1min nodeJS process",
2000,
() => {
pm2.start({
name: 'nodejs-process',
cwd: './tester/with-new/process1',
restartAt: [100, 1000, 30000],
restartOk: 60000,
}, (err, pid) => {
if(err && pid) console.error(err, pid)
else if(err) console.error(err)
else if(pid) console.log(`PID: ${pid}`)
})
})
runTest("Access the environment in nodejs",
1000,
() => {
pm2.start({
name: 'nodejs-with-env',
script: 'env.js',
cwd: './tester/with-new/process2',
env: { ENV_VAL: "Ok" },
})
})
runTest("Access the environment in python",
1000,
() => {
pm2.start({
name: 'python-with-env',
script: './tester/with-new/process2/env.py',
env: { ENV_VAL: "Ok" },
})
})
runTest("Stop all processes",
3 * 60 * 1000,
() => {
pm2.stopAll((err) => {
if(err) console.error(err)
})
})