Skip to content

Commit bc713ce

Browse files
committed
tests: hardened JIT-ability of the test suite and broadened support for the TEST_NGINX_HOTLOOP environment variable.
This also harden various test cases and removes a few globals caught by the _G write guard.
1 parent ad9b810 commit bc713ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+574
-1832
lines changed

t/TestCore.pm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package t::TestCore;
2+
3+
use Test::Nginx::Socket::Lua -Base;
4+
use Cwd qw(cwd);
5+
6+
$ENV{TEST_NGINX_HOTLOOP} ||= 10;
7+
8+
our $pwd = cwd();
9+
10+
our $lua_package_path = './lib/?.lua;../lua-resty-lrucache/lib/?.lua;;';
11+
12+
our $init_by_lua_block = <<_EOC_;
13+
local verbose = false
14+
if verbose then
15+
local dump = require "jit.dump"
16+
dump.on("b", "$Test::Nginx::Util::ErrLogFile")
17+
else
18+
local v = require "jit.v"
19+
v.on("$Test::Nginx::Util::ErrLogFile")
20+
end
21+
22+
require "resty.core"
23+
jit.opt.start("hotloop=$ENV{TEST_NGINX_HOTLOOP}")
24+
-- jit.off()
25+
_EOC_
26+
27+
our $HttpConfig = <<_EOC_;
28+
lua_package_path '$lua_package_path';
29+
30+
init_by_lua_block {
31+
$t::TestCore::init_by_lua_block
32+
}
33+
_EOC_
34+
35+
our @EXPORT = qw(
36+
$pwd
37+
$lua_package_path
38+
$init_by_lua_block
39+
$HttpConfig
40+
);
41+
42+
add_block_preprocessor(sub {
43+
my $block = shift;
44+
45+
if (!defined $block->http_config) {
46+
$block->set_value("http_config", $HttpConfig);
47+
}
48+
});
49+
50+
1;

t/TestCore/Stream.pm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package t::TestCore::Stream;
2+
3+
use Test::Nginx::Socket::Lua::Stream -Base;
4+
use Cwd qw(cwd);
5+
6+
$ENV{TEST_NGINX_HOTLOOP} ||= 10;
7+
8+
our $pwd = cwd();
9+
10+
our $lua_package_path = './lib/?.lua;../lua-resty-lrucache/lib/?.lua;;';
11+
12+
our $init_by_lua_block = <<_EOC_;
13+
local verbose = false
14+
if verbose then
15+
local dump = require "jit.dump"
16+
dump.on("b", "$Test::Nginx::Util::ErrLogFile")
17+
else
18+
local v = require "jit.v"
19+
v.on("$Test::Nginx::Util::ErrLogFile")
20+
end
21+
22+
require "resty.core"
23+
jit.opt.start("hotloop=$ENV{TEST_NGINX_HOTLOOP}")
24+
-- jit.off()
25+
_EOC_
26+
27+
our $StreamConfig = <<_EOC_;
28+
lua_package_path '$lua_package_path';
29+
30+
init_by_lua_block {
31+
$t::TestCore::Stream::init_by_lua_block
32+
}
33+
_EOC_
34+
35+
our @EXPORT = qw(
36+
$pwd
37+
$lua_package_path
38+
$init_by_lua_block
39+
$StreamConfig
40+
);
41+
42+
add_block_preprocessor(sub {
43+
my $block = shift;
44+
45+
if (!defined $block->stream_config) {
46+
$block->set_value("stream_config", $StreamConfig);
47+
}
48+
});
49+
50+
1;

t/balancer-timeout.t

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ BEGIN {
2020
$ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1;
2121
}
2222

23-
use Test::Nginx::Socket::Lua;
24-
use Cwd qw(cwd);
23+
use lib '.';
24+
use t::TestCore;
2525

2626
#worker_connections(1014);
2727
#master_on();
@@ -32,7 +32,7 @@ repeat_each(2);
3232

3333
plan tests => repeat_each() * (blocks() * 4);
3434

35-
$ENV{TEST_NGINX_CWD} = cwd();
35+
$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = $t::TestCore::lua_package_path;
3636

3737
#worker_connections(1024);
3838
#no_diff();
@@ -43,7 +43,7 @@ __DATA__
4343
4444
=== TEST 1: set_timeouts
4545
--- http_config
46-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
46+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
4747
4848
upstream backend {
4949
server 0.0.0.1;
@@ -77,7 +77,7 @@ event timer add: \d+: 7689:
7777
7878
=== TEST 2: set_timeouts (nil connect timeout)
7979
--- http_config
80-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
80+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
8181
proxy_connect_timeout 1234ms;
8282
8383
upstream backend {
@@ -112,7 +112,7 @@ event timer add: \d+: 7689:
112112
113113
=== TEST 3: set_timeouts (nil send timeout)
114114
--- http_config
115-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
115+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
116116
proxy_send_timeout 5678ms;
117117
118118
upstream backend {
@@ -147,7 +147,7 @@ event timer add: \d+: 7689:
147147
148148
=== TEST 4: set_timeouts (nil read timeout)
149149
--- http_config
150-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
150+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
151151
proxy_read_timeout 7689ms;
152152
153153
upstream backend {
@@ -182,7 +182,7 @@ event timer add: \d+: 7689:
182182
183183
=== TEST 5: set connect timeout to 0
184184
--- http_config
185-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
185+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
186186
187187
upstream backend {
188188
server 0.0.0.1;
@@ -213,7 +213,7 @@ qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/
213213
214214
=== TEST 6: set connect timeout to -1
215215
--- http_config
216-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
216+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
217217
218218
upstream backend {
219219
server 0.0.0.1;
@@ -244,7 +244,7 @@ qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/
244244
245245
=== TEST 7: set send timeout to 0
246246
--- http_config
247-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
247+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
248248
249249
upstream backend {
250250
server 0.0.0.1;
@@ -275,7 +275,7 @@ qr/\[error\] .*? balancer_by_lua:4: bad send timeout/
275275
276276
=== TEST 8: set send timeout to -1
277277
--- http_config
278-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
278+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
279279
280280
upstream backend {
281281
server 0.0.0.1;
@@ -306,7 +306,7 @@ qr/\[error\] .*? balancer_by_lua:4: bad send timeout/
306306
307307
=== TEST 9: set read timeout to -1
308308
--- http_config
309-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
309+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
310310
311311
upstream backend {
312312
server 0.0.0.1;
@@ -337,7 +337,7 @@ qr/\[error\] .*? balancer_by_lua:4: bad read timeout/
337337
338338
=== TEST 10: set_timeouts called in a wrong context
339339
--- http_config
340-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
340+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
341341
342342
--- config
343343
@@ -365,7 +365,7 @@ failed to call: no upstream found
365365
366366
=== TEST 11: set_timeouts called with a non-numerical parameter
367367
--- http_config
368-
lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;";
368+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
369369
370370
upstream backend {
371371
server 0.0.0.1;

0 commit comments

Comments
 (0)