Skip to content

Commit 920b5d7

Browse files
jinhua.tanrainingmaster
jinhua.tan
authored andcommitted
test: add some test cases with HUP to reload, and fix the num of cases.
1 parent ee46715 commit 920b5d7

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed

src/ngx_http_lua_directive.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,6 @@ ngx_http_lua_exit_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
12281228
ngx_str_t *value;
12291229
ngx_http_lua_main_conf_t *lmcf = conf;
12301230

1231-
dd("enter");
1232-
12331231
/* must specify a content handler */
12341232
if (cmd->post == NULL) {
12351233
return NGX_CONF_ERROR;

t/089-phase.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ log_level('warn');
88

99
repeat_each(2);
1010

11-
plan tests => repeat_each() * (blocks() * 2 + 1);
11+
plan tests => repeat_each() * (blocks() * 2) + 3;
1212

1313
#no_diff();
1414
#no_long_string();
@@ -183,7 +183,7 @@ init_worker
183183
--- http_config
184184
exit_worker_by_lua_block {
185185
local phase = ngx.get_phase()
186-
ngx.log(ngx.NOTICE, phase)
186+
ngx.log(ngx.ERR, phase)
187187
}
188188
--- config
189189
location /lua {
@@ -196,4 +196,4 @@ GET /lua
196196
--- response_body
197197
ok
198198
--- shutdown_error_log
199-
exit_worker
199+
exit_worker_by_lua:3: exit_worker

t/151-exit-worker.t renamed to t/162-exit-worker.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
44

55
repeat_each(2);
66

7-
plan tests => repeat_each() * (blocks() * 2);
7+
plan tests => repeat_each() * (blocks() * 2 + 2);
88

99
#log_level("warn");
1010
no_long_string();

t/163-exit-worker-hup.t

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
2+
3+
our $SkipReason;
4+
5+
BEGIN {
6+
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
7+
$SkipReason = "unavailable for the hup tests";
8+
9+
} else {
10+
$ENV{TEST_NGINX_USE_HUP} = 1;
11+
undef $ENV{TEST_NGINX_USE_STAP};
12+
}
13+
}
14+
15+
use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
16+
17+
repeat_each(2);
18+
19+
plan tests => repeat_each() * (blocks() * 2 + 2);
20+
21+
no_long_string();
22+
23+
worker_connections(1024);
24+
run_tests();
25+
26+
__DATA__
27+
28+
=== TEST 1: simple exit_worker_by_lua_block with hup
29+
--- http_config
30+
exit_worker_by_lua_block {
31+
ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block")
32+
}
33+
--- config
34+
location /t {
35+
content_by_lua_block {
36+
ngx.say("ok")
37+
}
38+
}
39+
--- request
40+
GET /t
41+
--- response_body
42+
ok
43+
--- shutdown_error_log
44+
log from exit_worker_by_lua_block
45+
46+
47+
48+
=== TEST 2: exit after worker_shutdown_timeout
49+
--- main_config
50+
worker_shutdown_timeout 1;
51+
--- http_config
52+
exit_worker_by_lua_block {
53+
ngx.log(ngx.NOTICE, "log from exit_worker_by_lua_block")
54+
}
55+
56+
server {
57+
listen 12345;
58+
59+
location = /t {
60+
echo 'hello world';
61+
}
62+
}
63+
--- config
64+
location /t {
65+
content_by_lua_block {
66+
ngx.timer.at(0, function ()
67+
local sock = ngx.socket.tcp()
68+
sock:connect("127.0.0.1", 12345)
69+
local reader = sock:receiveuntil("unknow")
70+
ngx.log(ngx.NOTICE, "reading to block the exiting")
71+
reader()
72+
end)
73+
74+
ngx.sleep(0)
75+
76+
ngx.say("ok")
77+
}
78+
}
79+
--- request
80+
GET /t
81+
--- response_body
82+
ok
83+
--- error_log
84+
reading to block the exiting
85+
--- shutdown_error_log
86+
log from exit_worker_by_lua_block

0 commit comments

Comments
 (0)