nic-6443 commented on code in PR #13536:
URL: https://github.com/apache/apisix/pull/13536#discussion_r3397945285
##########
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:
Good catch — with max_kept: 3 the count plateaus while rotation continues,
so the count was no stop signal at all. Reworked in 98edd84d8 to compare the
sorted timestamped file-name set instead. While verifying that, it turned out
the stronger check exposes a real reliability gap: the reload event sometimes
doesn't reach the privileged agent at all (rotation observed continuing for
55s+ on unmodified master, ~1 in 6 local runs under load), so the test now also
retries the reload until rotation stops — re-sending the event reliably lands
it, which confirms the unregister path itself is fine. Filing a separate issue
for the event-delivery gap with the reproduction details.
--
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]