You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "nic-6443 (via GitHub)" <gi...@apache.org> on 2026/06/11 17:16:44 UTC
[PR] test(log-rotate): deflake the disable-via-hot-reload case [apisix]
nic-6443 opened a new pull request, #13536:
URL: https://github.com/apache/apisix/pull/13536
### Description
t/plugin/log-rotate.t TEST 4 disables log-rotate via hot reload, sleeps a fixed 2.1s, and asserts at most one rotated file exists. But the reload event reaches the privileged agent (where the rotate timer runs) asynchronously — on a loaded runner the timer can tick twice before it is unregistered, and the test fails with `got: false`. It failed twice in a row on an unrelated PR (#13515) and reproduces locally roughly 1 in 6 runs under load, against unmodified master.
This rewrites the assertion to check the property the test actually cares about: rotation eventually stops after the plugin is disabled. It polls the rotated-file count and succeeds once no new file appears for two full rotation intervals (bounded by a 22s cap), which is immune to how long the agent takes to process the reload.
Test-only change.
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [ ] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(log-rotate): deflake the disable-via-hot-reload case [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(log-rotate): deflake the disable-via-hot-reload case [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 merged PR #13536:
URL: https://github.com/apache/apisix/pull/13536
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(log-rotate): deflake the disable-via-hot-reload case [apisix]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org