Skip to content

Commit 42341e7

Browse files
committed
test: add e2e tests for --update-env option
1 parent 83ea160 commit 42341e7

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

test/e2e.sh

100644100755
File mode changed.

test/e2e/cli/env-refresh.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,98 @@ $pm2 kill
8888
$pm2 l
8989
NODE_PATH='/test2' $pm2 start local_require.js -i 1
9090
should 'should have loaded the right globalPaths' 'restart_time: 0' 1
91+
92+
#
93+
# Ensuring that environment update works correctly when reloading with JSON config.
94+
#
95+
# Related issue:
96+
# https://github.com/Unitech/pm2/issues/3192
97+
#
98+
99+
# start with config
100+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
101+
>out-env.log
102+
103+
sleep 0.5
104+
grep "SH=shell_initial PM=pm2_initial SH_PM=pm2_initial" out-env.log &> /dev/null
105+
spec "should inject shell environment, then inject config environment on start with config"
106+
107+
# restart config without --update-env
108+
$pm2 delete all
109+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
110+
SH=shell_updated SH_PM=shell_updated $pm2 restart update-env.config.js --env updated
111+
>out-env.log
112+
113+
sleep 0.5
114+
grep "SH=shell_updated PM=pm2_updated SH_PM=pm2_updated" out-env.log &> /dev/null
115+
spec "should inject shell environment, then inject config environment on restart with config and without --update-env option"
116+
117+
# reload config without --update-env
118+
$pm2 delete all
119+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
120+
SH=shell_updated SH_PM=shell_updated $pm2 reload update-env.config.js --env updated
121+
>out-env.log
122+
123+
sleep 0.5
124+
grep "SH=shell_updated PM=pm2_updated SH_PM=pm2_updated" out-env.log &> /dev/null
125+
spec "should inject shell environment, then inject config environment on reload with config and without --update-env option"
126+
127+
# restart config with --update-env
128+
$pm2 delete all
129+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
130+
SH=shell_updated SH_PM=shell_updated $pm2 restart update-env.config.js --env updated --update-env
131+
>out-env.log
132+
133+
sleep 0.5
134+
grep "SH=shell_updated PM=pm2_updated SH_PM=pm2_updated" out-env.log &> /dev/null
135+
spec "should inject shell environment, then inject config environment on restart with config and with --update-env option"
136+
137+
# reload config with --update-env
138+
$pm2 delete all
139+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
140+
SH=shell_updated SH_PM=shell_updated $pm2 reload update-env.config.js --env updated --update-env
141+
>out-env.log
142+
143+
sleep 0.5
144+
grep "SH=shell_updated PM=pm2_updated SH_PM=pm2_updated" out-env.log &> /dev/null
145+
spec "should inject shell environment, then inject config environment on reload with config and with --update-env option"
146+
147+
# restart pid without --update-env
148+
$pm2 delete all
149+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
150+
SH=shell_updated SH_PM=shell_updated $pm2 restart update_env_app
151+
>out-env.log
152+
153+
sleep 0.5
154+
grep "SH=shell_initial PM=pm2_initial SH_PM=pm2_initial" out-env.log &> /dev/null
155+
spec "should keep environment on restart with pid and without --update-env option"
156+
157+
# reload pid without --update-env
158+
$pm2 delete all
159+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
160+
SH=shell_updated SH_PM=shell_updated $pm2 reload update_env_app
161+
>out-env.log
162+
163+
sleep 0.5
164+
grep "SH=shell_initial PM=pm2_initial SH_PM=pm2_initial" out-env.log &> /dev/null
165+
spec "should keep environment on reload with pid and without --update-env option"
166+
167+
# restart pid with --update-env
168+
$pm2 delete all
169+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
170+
SH=shell_updated SH_PM=shell_updated $pm2 restart update_env_app --update-env
171+
>out-env.log
172+
173+
sleep 0.5
174+
grep "SH=shell_updated PM=pm2_initial SH_PM=shell_updated" out-env.log &> /dev/null
175+
spec "should inject shell environment on restart with pid and with --update-env option"
176+
177+
# reload pid with --update-env
178+
$pm2 delete all
179+
SH=shell_initial SH_PM=shell_initial $pm2 start update-env.config.js --env initial
180+
SH=shell_updated SH_PM=shell_updated $pm2 reload update_env_app --update-env
181+
>out-env.log
182+
183+
sleep 0.5
184+
grep "SH=shell_updated PM=pm2_initial SH_PM=shell_updated" out-env.log &> /dev/null
185+
spec "should inject shell environment on reload with pid and with --update-env option"

test/fixtures/update-env.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: 'update_env_app',
5+
script: './update-env.js',
6+
instances: 2,
7+
exec_mode: 'cluster',
8+
out_file: 'out-env.log',
9+
merge_logs: true,
10+
env_initial: {
11+
NODE_ENV: 'test',
12+
PM: 'pm2_initial',
13+
SH_PM: 'pm2_initial',
14+
},
15+
env_updated: {
16+
NODE_ENV: 'test',
17+
PM: 'pm2_updated',
18+
SH_PM: 'pm2_updated',
19+
},
20+
},
21+
],
22+
};

test/fixtures/update-env.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
setInterval(() => {
2+
const { SH, PM, SH_PM } = process.env;
3+
4+
console.log(`SH=${SH} PM=${PM} SH_PM=${SH_PM}`);
5+
}, 100);

test/programmatic/env_switching.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('PM2 programmatic calls', function() {
131131
});
132132

133133
/**
134-
* Ensuring that environment update works correct when reloading with JSON config.
134+
* Ensuring that environment update works correctly when reloading with JSON config.
135135
*
136136
* Related issue:
137137
* https://github.com/Unitech/pm2/issues/3192

0 commit comments

Comments
 (0)