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 6e51dcfb7 test(cli): wait for the pid file before reading it (#13854)
6e51dcfb7 is described below
commit 6e51dcfb71781a1cd078e6e95c31711beaaaaf01
Author: Nic <[email protected]>
AuthorDate: Thu Aug 20 16:03:03 2026 +0800
test(cli): wait for the pid file before reading it (#13854)
---
t/cli/common.sh | 21 +++++++++++++++++++++
t/cli/test_cmd.sh | 1 +
2 files changed, 22 insertions(+)
diff --git a/t/cli/common.sh b/t/cli/common.sh
index 107d41a1a..2578f7ae5 100644
--- a/t/cli/common.sh
+++ b/t/cli/common.sh
@@ -39,6 +39,27 @@ exit_if_not_customed_nginx() {
openresty -V 2>&1 | grep apisix-nginx-module || exit 0
}
+# wait_for_pidfile <path> [timeout_secs]
+# Poll until the pid file exists and is non-empty; default timeout 10s.
+# `apisix start` returns once nginx has daemonized, which is before the master
+# has written its pid file, so reading the file right after is a race.
+wait_for_pidfile() {
+ local path="$1"
+ local timeout="${2:-10}"
+ local deadline=$(( $(date +%s) + timeout ))
+ { set +x; } 2>/dev/null
+ while [ "$(date +%s)" -lt "$deadline" ]; do
+ if [ -s "$path" ]; then
+ set -x
+ return 0
+ fi
+ sleep 0.1
+ done
+ set -x
+ echo "wait_for_pidfile: ${path} not written after ${timeout}s" >&2
+ return 1
+}
+
# wait_for_tcp <host> <port> [timeout_secs]
# Poll until the port accepts TCP; default timeout 10s. Bash-only (/dev/tcp,
local).
wait_for_tcp() {
diff --git a/t/cli/test_cmd.sh b/t/cli/test_cmd.sh
index a5375dc24..389426361 100755
--- a/t/cli/test_cmd.sh
+++ b/t/cli/test_cmd.sh
@@ -36,6 +36,7 @@ rm logs/nginx.pid || true
# check no corresponding process
make run
+wait_for_pidfile logs/nginx.pid
oldpid=$(< logs/nginx.pid)
make stop
sleep 0.5