Skip to content

Commit 2f061bf

Browse files
committed
tests: 058-tcp-socket.t: ported new tests added to the ngx_http_lua module.
1 parent 9563dd1 commit 2f061bf

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

t/058-tcp-socket.t

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua::Stream;
44

55
repeat_each(2);
66

7-
plan tests => repeat_each() * 191;
7+
plan tests => repeat_each() * 196;
88

99
our $HtmlDir = html_dir;
1010

@@ -3074,7 +3074,65 @@ failed to setkeepalive: closed
30743074
30753075
30763076
3077-
=== TEST 57: TEST 62: the upper bound of port range should be 2^16 - 1
3077+
=== TEST 57: options_table is nil
3078+
--- stream_server_config
3079+
content_by_lua_block {
3080+
local sock = ngx.socket.tcp()
3081+
local port = $TEST_NGINX_SERVER_PORT
3082+
3083+
local ok, err = sock:connect("127.0.0.1", port, nil)
3084+
if not ok then
3085+
ngx.say("failed to connect: ", err)
3086+
return
3087+
end
3088+
3089+
ngx.say("connected: ", ok)
3090+
3091+
ok, err = sock:close()
3092+
ngx.say("close: ", ok, " ", err)
3093+
}
3094+
--- stream_response
3095+
connected: 1
3096+
close: 1 nil
3097+
--- no_error_log
3098+
[error]
3099+
3100+
3101+
3102+
=== TEST 58: resolver send query failing immediately in connect()
3103+
this case did not clear coctx->cleanup properly and would lead to memory invalid accesses.
3104+
3105+
this test case requires the following iptables rule to work properly:
3106+
3107+
sudo iptables -I OUTPUT 1 -p udp --dport 10086 -j REJECT
3108+
3109+
--- stream_server_config
3110+
resolver 127.0.0.1:10086 ipv6=off;
3111+
resolver_timeout 10ms;
3112+
3113+
content_by_lua_block {
3114+
local sock = ngx.socket.tcp()
3115+
3116+
for i = 1, 3 do -- retry
3117+
local ok, err = sock:connect("www.google.com", 80)
3118+
if not ok then
3119+
ngx.say("failed to connect: ", err)
3120+
end
3121+
end
3122+
3123+
ngx.say("hello!")
3124+
}
3125+
--- stream_response_body_like
3126+
failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
3127+
failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
3128+
failed to connect: www.google.com could not be resolved(?: \(\d+: Operation timed out\))?
3129+
hello!
3130+
--- error_log eval
3131+
qr{\[alert\] .*? send\(\) failed \(\d+: Operation not permitted\) while resolving}
3132+
3133+
3134+
3135+
=== TEST 59: the upper bound of port range should be 2^16 - 1
30783136
--- stream_server_config
30793137
content_by_lua_block {
30803138
local sock, err = ngx.socket.connect("127.0.0.1", 65536)
@@ -3090,7 +3148,7 @@ failed to connect: bad port number: 65536
30903148
30913149
30923150
3093-
=== TEST 58: TCP socket GC'ed in preread phase without Lua content phase
3151+
=== TEST 60: TCP socket GC'ed in preread phase without Lua content phase
30943152
--- stream_server_config
30953153
lua_socket_connect_timeout 1s;
30963154
resolver $TEST_NGINX_RESOLVER ipv6=off;

0 commit comments

Comments
 (0)