Skip to content

Commit af2d357

Browse files
committed
added a (passing) fuzz testing for aborting many pending timers.
1 parent 3b3239c commit af2d357

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

t/109-timer-hup.t

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ our $StapScript = $t::StapThread::StapScript;
2828

2929
repeat_each(2);
3030

31-
plan tests => repeat_each() * 76;
31+
plan tests => repeat_each() * 81;
3232

3333
#no_diff();
3434
no_long_string();
@@ -439,3 +439,66 @@ failed to register a new timer after reload
439439
--- grep_error_log_out
440440
lua found 1 pending timers
441441
442+
443+
444+
=== TEST 6: HUP reload should abort pending timers (fuzz test)
445+
--- http_config
446+
lua_max_pending_timers 8192;
447+
448+
--- config
449+
location /t {
450+
content_by_lua '
451+
local job = function(premature, kill)
452+
if premature then
453+
return
454+
end
455+
456+
if kill then
457+
local f, err = io.open("t/servroot/logs/nginx.pid", "r")
458+
if not f then
459+
ngx.log(ngx.ERR, "failed to open nginx.pid: ", err)
460+
return
461+
end
462+
local pid = f:read()
463+
-- ngx.say("master pid: [", pid, "]")
464+
f:close()
465+
466+
os.execute("kill -HUP " .. pid)
467+
end
468+
end
469+
470+
math.randomseed(ngx.time())
471+
local rand = math.random
472+
local newtimer = ngx.timer.at
473+
for i = 1, 8191 do
474+
local delay = rand(4096)
475+
local ok, err = newtimer(delay, job, false)
476+
if not ok then
477+
ngx.say("failed to create timer at ", delay, ": ", err)
478+
return
479+
end
480+
end
481+
local ok, err = newtimer(0, job, true)
482+
if not ok then
483+
ngx.say("failed to create the killer timer: ", err)
484+
return
485+
end
486+
ngx.say("ok")
487+
';
488+
}
489+
--- request
490+
GET /t
491+
492+
--- response_body
493+
ok
494+
495+
--- wait: 0.3
496+
--- no_error_log
497+
[error]
498+
[alert]
499+
500+
--- grep_error_log eval: qr/lua found \d+ pending timers/
501+
--- grep_error_log_out
502+
lua found 8191 pending timers
503+
--- timeout: 20
504+

0 commit comments

Comments
 (0)