Skip to content

Commit 0e44ac6

Browse files
committed
tests: 106-timer.t: ported ngx_http_lua test cases for failed timers logging function definition location.
1 parent bbb0ae8 commit 0e44ac6

File tree

1 file changed

+124
-1
lines changed

1 file changed

+124
-1
lines changed

t/106-timer.t

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

1313
repeat_each(2);
1414

15-
plan tests => repeat_each() * (blocks() * 8 + 49);
15+
plan tests => repeat_each() * (blocks() * 8 + 46);
1616

1717
#no_diff();
1818
no_long_string();
@@ -1787,3 +1787,126 @@ ok
17871787
--- error_log
17881788
Bad bad bad
17891789
--- skip_nginx: 4: < 1.7.1
1790+
1791+
1792+
1793+
=== TEST 30: log function location when failed to run a timer
1794+
--- stream_config
1795+
lua_max_running_timers 1;
1796+
--- stream_server_config
1797+
content_by_lua_block {
1798+
local function g()
1799+
ngx.sleep(0.01)
1800+
end
1801+
1802+
local function f()
1803+
ngx.sleep(0.01)
1804+
end
1805+
1806+
local ok, err = ngx.timer.at(0, f)
1807+
if not ok then
1808+
ngx.say("failed to create timer f: ", err)
1809+
return
1810+
end
1811+
1812+
local ok, err = ngx.timer.at(0, g)
1813+
if not ok then
1814+
ngx.say("failed to create timer g: ", err)
1815+
return
1816+
end
1817+
1818+
ngx.say("ok")
1819+
}
1820+
--- stream_response
1821+
ok
1822+
--- wait: 0.1
1823+
--- error_log eval
1824+
qr/\[alert\] .*? lua failed to run timer with function defined at =content_by_lua\(nginx.conf:\d+\):2: stream lua: 1 lua_max_running_timers are not enough/
1825+
--- no_error_log
1826+
[emerg]
1827+
[crit]
1828+
[error]
1829+
[warn]
1830+
1831+
1832+
1833+
=== TEST 31: log function location when failed to run a timer (anonymous function)
1834+
--- stream_config
1835+
lua_max_running_timers 1;
1836+
--- stream_server_config
1837+
content_by_lua_block {
1838+
local function f()
1839+
ngx.sleep(0.01)
1840+
end
1841+
1842+
local ok, err = ngx.timer.at(0, f)
1843+
if not ok then
1844+
ngx.say("failed to set timer f: ", err)
1845+
return
1846+
end
1847+
1848+
local ok, err = ngx.timer.at(0, function()
1849+
ngx.sleep(0.01)
1850+
end)
1851+
1852+
if not ok then
1853+
ngx.say("failed to set timer: ", err)
1854+
return
1855+
end
1856+
1857+
ngx.say("ok")
1858+
}
1859+
--- stream_response
1860+
ok
1861+
--- wait: 0.1
1862+
--- error_log eval
1863+
qr/\[alert\] .*? lua failed to run timer with function defined at =content_by_lua\(nginx.conf:\d+\):12: stream lua: 1 lua_max_running_timers are not enough/
1864+
--- no_error_log
1865+
[emerg]
1866+
[crit]
1867+
[error]
1868+
[warn]
1869+
1870+
1871+
1872+
=== TEST 32: log function location when failed to run a timer (lua file)
1873+
--- user_files
1874+
>>> test.lua
1875+
local _M = {}
1876+
1877+
function _M.run()
1878+
ngx.sleep(0.01)
1879+
end
1880+
1881+
return _M
1882+
--- stream_config
1883+
lua_package_path '$TEST_NGINX_HTML_DIR/?.lua;./?.lua;;';
1884+
lua_max_running_timers 1;
1885+
--- stream_server_config
1886+
content_by_lua_block {
1887+
local test = require "test"
1888+
1889+
local ok, err = ngx.timer.at(0, test.run)
1890+
if not ok then
1891+
ngx.say("failed to set timer: ", err)
1892+
return
1893+
end
1894+
1895+
local ok, err = ngx.timer.at(0, test.run)
1896+
if not ok then
1897+
ngx.say("failed to set timer: ", err)
1898+
return
1899+
end
1900+
1901+
ngx.say("ok")
1902+
}
1903+
--- stream_response
1904+
ok
1905+
--- wait: 0.1
1906+
--- error_log eval
1907+
qr/\[alert\] .*? lua failed to run timer with function defined at @.+\/test.lua:3: stream lua: 1 lua_max_running_timers are not enough/
1908+
--- no_error_log
1909+
[emerg]
1910+
[crit]
1911+
[error]
1912+
[warn]

0 commit comments

Comments
 (0)