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