Skip to content

Commit 3bbf27b

Browse files
committed
Fix MacOS broker test.
1 parent 727d9d5 commit 3bbf27b

2 files changed

Lines changed: 70 additions & 11 deletions

File tree

.github/workflows/macos-check.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,36 @@ jobs:
8484
- name: Show logs on failure
8585
if: failure() || cancelled()
8686
run: |
87-
cat test-suite.log
88-
cat scripts/*.log
87+
# Copy broker.test tmp dirs ($TMPDIR/tmp.* on macOS, e.g.
88+
# /var/folders/.../T/tmp.XXXXXX) into the workspace so the
89+
# next step can upload them as an artifact. Globbing the
90+
# real /var/folders path directly trips over unreadable
91+
# macOS LaunchServices files.
92+
mkdir -p ci-logs
93+
[ -f test-suite.log ] && cp test-suite.log ci-logs/ || true
94+
cp scripts/*.log ci-logs/ 2>/dev/null || true
95+
for d in "${TMPDIR%/}"/tmp.* /tmp/tmp.*; do
96+
[ -d "$d" ] || continue
97+
base=$(basename "$d")
98+
mkdir -p "ci-logs/$base"
99+
cp "$d"/*.log "ci-logs/$base/" 2>/dev/null || true
100+
done
101+
echo "=== test-suite.log ==="
102+
cat test-suite.log 2>/dev/null || true
103+
echo "=== scripts/*.log ==="
104+
cat scripts/*.log 2>/dev/null || true
105+
echo "=== ci-logs/tmp.*/*.log (broker.test per-test logs) ==="
106+
for f in ci-logs/tmp.*/*.log; do
107+
[ -f "$f" ] || continue
108+
echo "--- $f ---"
109+
cat "$f"
110+
done
111+
112+
- name: Upload broker.test logs on failure
113+
if: failure() || cancelled()
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: broker-test-logs-macos
117+
path: ci-logs/
118+
if-no-files-found: ignore
119+
retention-days: 7

scripts/broker.test

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ start_broker() {
108108
tls_args="-s $port"
109109
fi
110110
broker_log="${TMP_DIR}/broker_p${port}.log"
111-
./$broker_bin "$@" -p $port $tls_args >"$broker_log" 2>&1 &
111+
# -v 3 = DEBUG; emits PUBLISH/PUBACK/drain events so the
112+
# preserved broker_p<port>.log makes broker-side failures
113+
# actually diagnosable in CI.
114+
./$broker_bin "$@" -v 3 -p $port $tls_args >"$broker_log" 2>&1 &
112115
broker_pid=$!
113116
if check_broker; then
114117
return 0
@@ -136,7 +139,7 @@ start_broker_dual() {
136139
port_tls=$port
137140
port=$plain_port
138141
broker_log="${TMP_DIR}/broker_dual_p${port}_t${port_tls}.log"
139-
./$broker_bin "$@" -p $port -s $port_tls >"$broker_log" 2>&1 &
142+
./$broker_bin "$@" -v 3 -p $port -s $port_tls >"$broker_log" 2>&1 &
140143
broker_pid=$!
141144
check_broker $port
142145
check_broker $port_tls
@@ -1135,27 +1138,45 @@ else
11351138
start_broker
11361139
T26_N=20
11371140
rm -f "${TMP_DIR}/t26_sub.ready"
1138-
timeout 15 ./$sub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
1139-
-i "t26_sub" -C $T26_N -R "${TMP_DIR}/t26_sub.ready" \
1141+
# Notes on subscriber flags:
1142+
# -C 5000 command timeout per wait, in milliseconds. NOT a message
1143+
# count - mqtt-sub uses -C as cmd_timeout_ms (mqttexample.c
1144+
# case 'C'). Earlier revisions of this test mistakenly
1145+
# passed -C $T26_N (=20), giving a 20 ms timeout that on
1146+
# nonblock builds (--enable-all enables WOLFMQTT_NONBLOCK)
1147+
# tripped MqttClient_Unsubscribe / Ping_ex before any
1148+
# output flushed, especially on macOS arm64.
1149+
# -k 300 keep-alive seconds; bumped above worst-case test duration
1150+
# so the client-side keep-alive does not fire mid-burst on
1151+
# slow CI runners. Inbound PUBLISH traffic does not reset
1152+
# the client keep-alive timer.
1153+
# Subscriber stays alive until the test kills it after the publishers
1154+
# finish; that pattern is below.
1155+
timeout 30 ./$sub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
1156+
-i "t26_sub" -C 5000 -k 300 -R "${TMP_DIR}/t26_sub.ready" \
11401157
>"${TMP_DIR}/t26_sub.log" 2>&1 &
11411158
T26_SUB_PID=$!
11421159
TEST_PIDS+=($T26_SUB_PID)
1143-
wait_for_file "${TMP_DIR}/t26_sub.ready" 5
1160+
wait_for_file "${TMP_DIR}/t26_sub.ready" 10
11441161
# Publish T26_N sequentially numbered QoS 1 messages
11451162
for t26_i in $(seq 1 $T26_N); do
11461163
./$pub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
11471164
-m "burst_${t26_i}" -i "t26_pub_${t26_i}" \
11481165
>>"${TMP_DIR}/t26_pub.log" 2>&1
11491166
done
1150-
# Give the subscriber a moment to drain.
1151-
sleep 1
1167+
# mqtt-sub has no "exit after N messages" mode, so it never exits on
1168+
# its own. Give the broker a grace window to fan out all 20 messages
1169+
# (each publisher is a separate connect/pub/disconnect; the broker's
1170+
# outbound drain may lag the last publish a bit on slow CI), then kill
1171+
# the subscriber so its log is flushed and we can count what arrived.
1172+
sleep 2
11521173
kill $T26_SUB_PID 2>/dev/null
11531174
wait $T26_SUB_PID 2>/dev/null || true
11541175
TEST_PIDS=()
11551176
# Count how many of the burst_N tokens reached the subscriber and check
11561177
# that they arrived in publish order (1, 2, ..., N).
11571178
T26_RECEIVED=$(grep -oE 'burst_[0-9]+' "${TMP_DIR}/t26_sub.log" 2>/dev/null \
1158-
| wc -l)
1179+
| wc -l | tr -d ' ')
11591180
T26_ORDER_OK=yes
11601181
T26_LAST=0
11611182
while read -r tok; do
@@ -1165,11 +1186,18 @@ while read -r tok; do
11651186
fi
11661187
T26_LAST=$n
11671188
done < <(grep -oE 'burst_[0-9]+' "${TMP_DIR}/t26_sub.log" 2>/dev/null)
1168-
if [ "$T26_RECEIVED" = "$T26_N" ] && [ "$T26_ORDER_OK" = "yes" ]; then
1189+
if [ "$T26_RECEIVED" -eq "$T26_N" ] && [ "$T26_ORDER_OK" = "yes" ]; then
11691190
echo "PASS: QoS 1 burst delivery (received=$T26_RECEIVED order=ok)"
11701191
else
11711192
echo "FAIL: Burst delivery (received=$T26_RECEIVED expected=$T26_N " \
11721193
"order=$T26_ORDER_OK)"
1194+
echo "--- t26 broker_log tail ---"
1195+
tail -80 "$broker_log" 2>/dev/null || true
1196+
echo "--- t26_sub.log tail ---"
1197+
tail -40 "${TMP_DIR}/t26_sub.log" 2>/dev/null || true
1198+
echo "--- t26_pub.log tail ---"
1199+
tail -40 "${TMP_DIR}/t26_pub.log" 2>/dev/null || true
1200+
echo "--- t26 end ---"
11731201
FAIL=1
11741202
fi
11751203
fi # skip_plain

0 commit comments

Comments
 (0)