Skip to content

Commit 5169684

Browse files
committed
change: avoided running any init_by_lua* code when testing Nginx configuration.
1 parent 4e99dfc commit 5169684

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/ngx_http_lua_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ ngx_http_lua_init(ngx_conf_t *cf)
640640
#endif
641641
ngx_str_t name = ngx_string("host");
642642

643-
if (ngx_process == NGX_PROCESS_SIGNALLER) {
643+
if (ngx_process == NGX_PROCESS_SIGNALLER || ngx_test_config) {
644644
return NGX_OK;
645645
}
646646

t/157-disable-init-by-lua.t

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use Test::Nginx::Socket::Lua;
22

33
repeat_each(2);
44

5-
plan tests => repeat_each() * (blocks() * 3);
5+
plan tests => repeat_each() * (blocks() * 2);
66

77
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
88
my $html_dir = $ENV{TEST_NGINX_HTML_DIR};
@@ -15,6 +15,8 @@ my $http_config = <<_EOC_;
1515
}
1616
http {
1717
init_by_lua_block {
18+
-- if the code in the init_by_lua* is run, there
19+
-- will be a string contains the 'error'
1820
ngx.log(ngx.ERR, "run init_by_lua")
1921
}
2022
}
@@ -74,6 +76,49 @@ __DATA__
7476
return
7577
end
7678
79+
local out, err = p:read('*a')
80+
if not out then
81+
ngx.log(ngx.ERR, err)
82+
83+
else
84+
ngx.log(ngx.WARN, out)
85+
end
86+
}
87+
}
88+
--- no_error_log eval
89+
qr/\[error\] .+ (?!:nginx.pid" failed \(2: No such file or directory\))$/
90+
91+
92+
93+
=== TEST 2: ensure init_by_lua* is not run when testing Nginx configuration
94+
--- config
95+
location = /t {
96+
content_by_lua_block {
97+
local conf_file = set_up_ngx_tmp_conf()
98+
local nginx = get_ngx_bin_path()
99+
100+
local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -t"
101+
local p, err = io.popen(cmd)
102+
if not p then
103+
ngx.log(ngx.ERR, err)
104+
return
105+
end
106+
107+
local out, err = p:read('*a')
108+
if not out then
109+
ngx.log(ngx.ERR, err)
110+
111+
else
112+
ngx.log(ngx.WARN, out)
113+
end
114+
115+
local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -T"
116+
local p, err = io.popen(cmd)
117+
if not p then
118+
ngx.log(ngx.ERR, err)
119+
return
120+
end
121+
77122
local out, err = p:read('*a')
78123
if not out then
79124
ngx.log(ngx.ERR, err)
@@ -84,5 +129,4 @@ __DATA__
84129
}
85130
}
86131
--- no_error_log
87-
[error] .+ (?!:nginx.pid" failed \(2: No such file or directory\))
88-
run init_by_lua
132+
[error]

0 commit comments

Comments
 (0)