Skip to content

Commit 05f4402

Browse files
fanzu8hao022
authored andcommitted
test: lib: print if wait_until failed
Signed-off-by: fanzu8 <tuzengbing@gmail.com>
1 parent 387327c commit 05f4402

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

e2e/lib.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ assert_kubelet_pod_count() {
7575
assert_eq "$actual" "$expect" "$desc"
7676
}
7777

78-
wait_until \
78+
if ! wait_until \
7979
"$((WAIT_HUATUO_BAMAI_TIMEOUT / 2))" \
8080
"${WAIT_HUATUO_BAMAI_INTERVAL}" \
8181
"$desc" \
82-
_assert
82+
_assert; then
83+
# wait timeout, dump pods from kubelet
84+
kubelet_pods_json
85+
fi
8386
}
8487

8588
assert_huatuo_bamai_pod_count() {
@@ -90,11 +93,14 @@ assert_huatuo_bamai_pod_count() {
9093
assert_eq "$actual" "$expect" "$desc"
9194
}
9295

93-
wait_until \
96+
if ! wait_until \
9497
"$((WAIT_HUATUO_BAMAI_TIMEOUT / 2))" \
9598
"${WAIT_HUATUO_BAMAI_INTERVAL}" \
9699
"$desc" \
97-
_assert
100+
_assert; then
101+
# wait timeout, dump pods from huatuo-bamai
102+
curl "${CURL_TIMEOUT[@]}" ${HUATUO_BAMAI_PODS_API}
103+
fi
98104
}
99105

100106
e2e_test_teardown() {

integration/lib.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,36 @@ assert_eq() {
5151
}
5252

5353
# wait_until <timeout> <interval> <description> <function> [args...]
54-
# Example:
55-
# wait_until 10 1 "check ready" my_check_func "arg1" "arg2"
54+
# Returns: 0 on success, 1 on timeout (does not exit script)
5655
wait_until() {
5756
local timeout=$1 interval=$2 desc=$3
5857
shift 3
5958
local func=$1
6059
shift
6160

62-
if ! declare -f "$func" >/dev/null 2>&1; then
63-
fatal "❌ wait_until expects function or command: \"$func\""
61+
if ! type -t "$func" >/dev/null 2>&1; then
62+
echo "❌ wait_until expects function or command: \"$func\"" >&2
63+
return 1
6464
fi
6565

6666
local end=$(($(date +%s) + timeout))
6767
local attempt=0
68-
while (($(date +%s) < end)); do
68+
local ret=0
69+
70+
while [ "$(date +%s)" -lt "$end" ]; do
71+
ret=0
6972
attempt=$((attempt + 1))
70-
log_info "wait attempt #${attempt}: ${desc}"
71-
if "$func" "$@"; then
73+
log_info "wait attempt #${attempt}: ${desc}, func/cmd: [${func} ${@}]"
74+
"$func" "$@" || ret=$?
75+
if [ "$ret" -eq 0 ]; then
7276
return 0
7377
fi
78+
7479
sleep "$interval"
7580
done
7681

77-
fatal "❌ timeout waiting for: ${desc} after ${timeout}s"
82+
log_error "❌ wait_until timeout: ${desc}, func/cmd: [${func} ${@}]"
83+
return 1
7884
}
7985

8086
# ------------------------------- huatuo-bamai --------------------------------
@@ -88,6 +94,8 @@ huatuo_bamai_start() {
8894
${HUATUO_BAMAI_BIN} "${args[@]}" >${HUATUO_BAMAI_TEST_TMPDIR}/huatuo.log 2>&1 &
8995
HUATUO_BAMAI_PID=$!
9096

97+
sleep 0.5s
98+
9199
wait_until "${WAIT_HUATUO_BAMAI_TIMEOUT}" "${WAIT_HUATUO_BAMAI_INTERVAL}" "huatuo-bamai ready" \
92100
huatuo_bamai_ready
93101
}

0 commit comments

Comments
 (0)