Skip to content

Commit 70484bc

Browse files
committed
tweaks: ported adjustments and missing test cases from the ngx_stream_lua module.
1 parent 315330a commit 70484bc

File tree

4 files changed

+77
-22
lines changed

4 files changed

+77
-22
lines changed

src/ngx_http_lua_util.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
13521352

13531353
if (!ctx->cur_co_ctx->is_wrap) {
13541354
/*
1355-
* ended successful, coroutine.resume returns true plus
1355+
* ended successfully, coroutine.resume returns true plus
13561356
* any return values
13571357
*/
13581358
lua_pushboolean(next_co, success);
@@ -1520,7 +1520,7 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
15201520
if (orig_coctx->is_wrap) {
15211521
/*
15221522
* coroutine.wrap propagates errors
1523-
* to the parent
1523+
* to its parent coroutine
15241524
*/
15251525
next_coctx->propagate_error = 1;
15261526
continue;

t/058-tcp-socket.t

+48-10
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() * 219;
7+
plan tests => repeat_each() * 222;
88

99
our $HtmlDir = html_dir;
1010

@@ -3643,7 +3643,45 @@ lua http cleanup reuse
36433643
36443644
36453645
3646-
=== TEST 60: options_table is nil
3646+
=== TEST 60: setkeepalive on socket already shutdown
3647+
--- config
3648+
location /t {
3649+
set $port $TEST_NGINX_MEMCACHED_PORT;
3650+
3651+
content_by_lua_block {
3652+
local sock = ngx.socket.tcp()
3653+
local port = ngx.var.port
3654+
3655+
local ok, err = sock:connect("127.0.0.1", port)
3656+
if not ok then
3657+
ngx.say("failed to connect: ", err)
3658+
return
3659+
end
3660+
3661+
ngx.say("connected: ", ok)
3662+
3663+
local ok, err = sock:close()
3664+
if not ok then
3665+
ngx.log(ngx.ERR, "failed to close socket: ", err)
3666+
return
3667+
end
3668+
3669+
local ok, err = sock:setkeepalive()
3670+
if not ok then
3671+
ngx.log(ngx.ERR, "failed to setkeepalive: ", err)
3672+
end
3673+
}
3674+
}
3675+
--- request
3676+
GET /t
3677+
--- response_body
3678+
connected: 1
3679+
--- error_log
3680+
failed to setkeepalive: closed
3681+
3682+
3683+
3684+
=== TEST 61: options_table is nil
36473685
--- config
36483686
location /t {
36493687
set $port $TEST_NGINX_MEMCACHED_PORT;
@@ -3693,7 +3731,7 @@ close: 1 nil
36933731
36943732
36953733
3696-
=== TEST 61: resolver send query failing immediately in connect()
3734+
=== TEST 62: resolver send query failing immediately in connect()
36973735
this case did not clear coctx->cleanup properly and would lead to memory invalid accesses.
36983736
36993737
this test case requires the following iptables rule to work properly:
@@ -3730,7 +3768,7 @@ qr{\[alert\] .*? send\(\) failed \(\d+: Operation not permitted\) while resolvin
37303768
37313769
37323770
3733-
=== TEST 62: the upper bound of port range should be 2^16 - 1
3771+
=== TEST 63: the upper bound of port range should be 2^16 - 1
37343772
--- config
37353773
location /t {
37363774
content_by_lua_block {
@@ -3749,7 +3787,7 @@ failed to connect: bad port number: 65536
37493787
37503788
37513789
3752-
=== TEST 63: send boolean and nil
3790+
=== TEST 64: send boolean and nil
37533791
--- config
37543792
location /t {
37553793
set $port $TEST_NGINX_SERVER_PORT;
@@ -3811,7 +3849,7 @@ received: truefalsenil
38113849
38123850
38133851
3814-
=== TEST 64: receiveany method in cosocket
3852+
=== TEST 65: receiveany method in cosocket
38153853
--- config
38163854
server_tokens off;
38173855
location = /t {
@@ -3900,7 +3938,7 @@ lua tcp socket read any
39003938
39013939
39023940
3903-
=== TEST 65: receiveany send data after read side closed
3941+
=== TEST 66: receiveany send data after read side closed
39043942
--- config
39053943
server_tokens off;
39063944
location = /t {
@@ -3944,7 +3982,7 @@ GET /t
39443982
39453983
39463984
3947-
=== TEST 66: receiveany with limited, max <= 0
3985+
=== TEST 67: receiveany with limited, max <= 0
39483986
--- config
39493987
location = /t {
39503988
set $port $TEST_NGINX_SERVER_PORT;
@@ -3980,7 +4018,7 @@ GET /t
39804018
39814019
39824020
3983-
=== TEST 67: receiveany with limited, max is larger than data
4021+
=== TEST 68: receiveany with limited, max is larger than data
39844022
--- config
39854023
server_tokens off;
39864024
location = /t {
@@ -4049,7 +4087,7 @@ lua tcp socket calling receiveany() method to read at most 128 bytes
40494087
40504088
40514089
4052-
=== TEST 68: receiveany with limited, max is smaller than data
4090+
=== TEST 69: receiveany with limited, max is smaller than data
40534091
--- config
40544092
server_tokens off;
40554093
location = /t {

t/091-coroutine.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ co == co2: false
15331533
--- config
15341534
location = /t {
15351535
content_by_lua_block {
1536-
function f()
1536+
local function f()
15371537
local cnt = 0
15381538
for i = 1, 20 do
15391539
ngx.say("co yield: ", cnt)
@@ -1567,7 +1567,7 @@ co yield: 2
15671567
--- config
15681568
location = /t {
15691569
content_by_lua_block {
1570-
function f()
1570+
local function f()
15711571
local cnt = 0
15721572
for i = 1, 20 do
15731573
coroutine.yield(cnt, cnt + 1)
@@ -1601,7 +1601,7 @@ co yield: 2, 3
16011601
--- config
16021602
location = /t {
16031603
content_by_lua_block {
1604-
function f(step)
1604+
local function f(step)
16051605
local cnt = 0
16061606
for i = 1, 20 do
16071607
ngx.say("co yield: ", cnt)
@@ -1637,7 +1637,7 @@ co yield: 2
16371637
return 200;
16381638
16391639
header_filter_by_lua_block {
1640-
function f()
1640+
local function f()
16411641
local cnt = 0
16421642
for i = 1, 20 do
16431643
print("co yield: ", cnt)

t/161-load-resty-core.t

+23-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,24 @@ resty.core loaded: true
3838
3939
4040
41-
=== TEST 2: resty.core is automatically loaded in the Lua VM with 'lua_code_cache off'
41+
=== TEST 2: resty.core is automatically loaded in the Lua VM when 'lua_shared_dict' is used
42+
--- http_config
43+
lua_shared_dict dogs 128k;
44+
--- config
45+
location = /t {
46+
content_by_lua_block {
47+
local loaded_resty_core = package.loaded["resty.core"]
48+
local resty_core = require "resty.core"
49+
50+
ngx.say("resty.core loaded: ", loaded_resty_core == resty_core)
51+
}
52+
}
53+
--- response_body
54+
resty.core loaded: true
55+
56+
57+
58+
=== TEST 3: resty.core is automatically loaded in the Lua VM with 'lua_code_cache off'
4259
--- http_config
4360
lua_code_cache off;
4461
--- config
@@ -55,7 +72,7 @@ resty.core loaded: true
5572
5673
5774
58-
=== TEST 3: resty.core loading honors the lua_package_path directive
75+
=== TEST 4: resty.core loading honors the lua_package_path directive
5976
--- http_config eval
6077
"lua_package_path '$::HtmlDir/?.lua;;';"
6178
--- config
@@ -82,7 +99,7 @@ return {
8299
83100
84101
85-
=== TEST 4: resty.core not loading aborts the initialization
102+
=== TEST 5: resty.core not loading aborts the initialization
86103
--- http_config eval
87104
"lua_package_path '$::HtmlDir/?.lua;';"
88105
--- config
@@ -95,7 +112,7 @@ qr/\[alert\] .*? failed to load the 'resty\.core' module .*? \(reason: module 'r
95112
96113
97114
98-
=== TEST 5: resty.core not loading produces an error with 'lua_code_cache off'
115+
=== TEST 6: resty.core not loading produces an error with 'lua_code_cache off'
99116
--- http_config
100117
lua_code_cache off;
101118
@@ -116,7 +133,7 @@ qr/\[alert\] .*? failed to load the 'resty\.core' module/
116133
117134
118135
119-
=== TEST 6: lua_load_resty_core logs a deprecation warning when specified (on)
136+
=== TEST 7: lua_load_resty_core logs a deprecation warning when specified (on)
120137
--- http_config
121138
lua_load_resty_core on;
122139
--- config
@@ -132,7 +149,7 @@ qr/\[warn\] .*? lua_load_resty_core is deprecated \(the lua-resty-core library i
132149
133150
134151
135-
=== TEST 7: lua_load_resty_core logs a deprecation warning when specified (off)
152+
=== TEST 8: lua_load_resty_core logs a deprecation warning when specified (off)
136153
--- http_config
137154
lua_load_resty_core off;
138155
--- config

0 commit comments

Comments
 (0)