Copilot commented on code in PR #13536:
URL: https://github.com/apache/apisix/pull/13536#discussion_r3397822462
##########
t/plugin/log-rotate.t:
##########
@@ -158,21 +158,43 @@ plugins:
ngx.status = code
ngx.say(org_body)
- ngx.sleep(2.1) -- make sure two files will be rotated out if we
don't disable it
-
- local n_split_error_file = 0
local lfs = require("lfs")
- for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
- if string.match(file_name, "__error.log$") then
- n_split_error_file = n_split_error_file + 1
+ local function count_rotated_files()
+ local n = 0
+ for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
+ if string.match(file_name, "__error.log$") then
+ n = n + 1
+ end
end
+ return n
end
- -- Before hot reload, the log rotate may or may not take effect.
- -- It depends on the time we start the test
- ngx.say(n_split_error_file <= 1)
+ -- the reload event reaches the privileged agent asynchronously,
+ -- so a few more rotations may still happen before the timer is
+ -- unregistered; assert that the rotation eventually stops by
+ -- waiting until no new rotated file appears for two full
+ -- rotation intervals
+ local stopped = false
+ local last = count_rotated_files()
+ local stable = 0
+ for _ = 1, 20 do
+ ngx.sleep(1.1)
+ local cur = count_rotated_files()
Review Comment:
The new polling logic treats "rotation stopped" as "the number of rotated
__error.log files stops increasing". This can be a false positive once
log-rotate hits max_kept: the plugin can keep rotating while deleting the
oldest file each interval, so the *count* stays constant even though rotation
is still happening. To assert that rotation really stopped, compare a signature
of the rotated filenames (or mtimes) rather than just the count.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]