Skip to content

Commit 938d8bb

Browse files
committed
tests: ported ngx_http_lua test cases for TCP cosockets keepalive when worker process shuts down.
1 parent f3c2021 commit 938d8bb

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

t/157-socket-keepalive-hup.t

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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::Stream $SkipReason ? (skip_all => $SkipReason) : ();
16+
17+
repeat_each(2);
18+
19+
plan tests => repeat_each() * (blocks() * 8);
20+
21+
worker_connections(1024);
22+
no_long_string();
23+
run_tests();
24+
25+
__DATA__
26+
27+
=== TEST 1: exiting
28+
--- stream_server_config
29+
content_by_lua_block {
30+
local f, err = io.open("t/servroot/logs/nginx.pid", "r")
31+
if not f then
32+
ngx.say("failed to open nginx.pid: ", err)
33+
return
34+
end
35+
36+
local pid = f:read()
37+
-- ngx.say("master pid: [", pid, "]")
38+
39+
f:close()
40+
41+
local i = 0
42+
43+
local function f(premature)
44+
print("timer prematurely expired: ", premature)
45+
46+
local sock = ngx.socket.tcp()
47+
48+
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_SERVER_PORT)
49+
if not ok then
50+
print("failed to connect: ", err)
51+
return
52+
end
53+
54+
local ok, err = sock:setkeepalive()
55+
if not ok then
56+
print("failed to setkeepalive: ", err)
57+
return
58+
end
59+
60+
print("setkeepalive successfully")
61+
end
62+
local ok, err = ngx.timer.at(3, f)
63+
if not ok then
64+
ngx.say("failed to set timer: ", err)
65+
return
66+
end
67+
ngx.say("registered timer")
68+
os.execute("kill -HUP " .. pid)
69+
}
70+
--- stream_response
71+
registered timer
72+
--- wait: 0.3
73+
--- no_error_log
74+
[error]
75+
[alert]
76+
[crit]
77+
--- error_log
78+
timer prematurely expired: true
79+
setkeepalive successfully
80+
lua tcp socket set keepalive while process exiting, closing connection

0 commit comments

Comments
 (0)