This is an automated email from the ASF dual-hosted git repository.
nic-6443 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 46646a2d7 test(log-rotate): deflake the disable-via-hot-reload case
(#13536)
46646a2d7 is described below
commit 46646a2d7994baab34466fa6e59158ac4502819b
Author: Nic <[email protected]>
AuthorDate: Fri Jun 12 10:52:55 2026 +0800
test(log-rotate): deflake the disable-via-hot-reload case (#13536)
---
t/plugin/log-rotate.t | 49 ++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 9 deletions(-)
diff --git a/t/plugin/log-rotate.t b/t/plugin/log-rotate.t
index 8e6250766..4d88ae4e8 100644
--- a/t/plugin/log-rotate.t
+++ b/t/plugin/log-rotate.t
@@ -158,21 +158,52 @@ 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
+ -- the rotated file names are timestamped, so the signature
+ -- changes on every rotation even after max_kept is reached and
+ -- the file count plateaus
+ local function rotated_files_signature()
+ local names = {}
+ for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
+ if string.match(file_name, "__error.log$") then
+ table.insert(names, file_name)
+ end
end
+ table.sort(names)
+ return table.concat(names, ",")
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
+ -- and can be lost under load, so retry the reload until the
+ -- rotation stops: the rotated files staying unchanged for two
+ -- full rotation intervals means the timer was unregistered
+ local stopped = false
+ for _ = 1, 4 do
+ local last = rotated_files_signature()
+ local stable = 0
+ for _ = 1, 6 do
+ ngx.sleep(1.1)
+ local cur = rotated_files_signature()
+ if cur == last then
+ stable = stable + 1
+ if stable >= 2 then
+ stopped = true
+ break
+ end
+ else
+ stable = 0
+ last = cur
+ end
+ end
+ if stopped then
+ break
+ end
+ t('/apisix/admin/plugins/reload', ngx.HTTP_PUT)
+ end
+ ngx.say(stopped)
}
}
+--- timeout: 60
--- response_body
done
true