Skip to content

Commit 524bfae

Browse files
committed
Fix MacOS broker test.
1 parent 2a359cb commit 524bfae

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
@@ -1133,27 +1136,45 @@ else
11331136
start_broker
11341137
T26_N=20
11351138
rm -f "${TMP_DIR}/t26_sub.ready"
1136-
timeout 15 ./$sub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
1137-
-i "t26_sub" -C $T26_N -R "${TMP_DIR}/t26_sub.ready" \
1139+
# Notes on subscriber flags:
1140+
# -C 5000 command timeout per wait, in milliseconds. NOT a message
1141+
# count - mqtt-sub uses -C as cmd_timeout_ms (mqttexample.c
1142+
# case 'C'). Earlier revisions of this test mistakenly
1143+
# passed -C $T26_N (=20), giving a 20 ms timeout that on
1144+
# nonblock builds (--enable-all enables WOLFMQTT_NONBLOCK)
1145+
# tripped MqttClient_Unsubscribe / Ping_ex before any
1146+
# output flushed, especially on macOS arm64.
1147+
# -k 300 keep-alive seconds; bumped above worst-case test duration
1148+
# so the client-side keep-alive does not fire mid-burst on
1149+
# slow CI runners. Inbound PUBLISH traffic does not reset
1150+
# the client keep-alive timer.
1151+
# Subscriber stays alive until the test kills it after the publishers
1152+
# finish; that pattern is below.
1153+
timeout 30 ./$sub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
1154+
-i "t26_sub" -C 5000 -k 300 -R "${TMP_DIR}/t26_sub.ready" \
11381155
>"${TMP_DIR}/t26_sub.log" 2>&1 &
11391156
T26_SUB_PID=$!
11401157
TEST_PIDS+=($T26_SUB_PID)
1141-
wait_for_file "${TMP_DIR}/t26_sub.ready" 5
1158+
wait_for_file "${TMP_DIR}/t26_sub.ready" 10
11421159
# Publish T26_N sequentially numbered QoS 1 messages
11431160
for t26_i in $(seq 1 $T26_N); do
11441161
./$pub_bin -T -h 127.0.0.1 -p $port -n "test/burst" -q 1 \
11451162
-m "burst_${t26_i}" -i "t26_pub_${t26_i}" \
11461163
>>"${TMP_DIR}/t26_pub.log" 2>&1
11471164
done
1148-
# Give the subscriber a moment to drain.
1149-
sleep 1
1165+
# mqtt-sub has no "exit after N messages" mode, so it never exits on
1166+
# its own. Give the broker a grace window to fan out all 20 messages
1167+
# (each publisher is a separate connect/pub/disconnect; the broker's
1168+
# outbound drain may lag the last publish a bit on slow CI), then kill
1169+
# the subscriber so its log is flushed and we can count what arrived.
1170+
sleep 2
11501171
kill $T26_SUB_PID 2>/dev/null
11511172
wait $T26_SUB_PID 2>/dev/null || true
11521173
TEST_PIDS=()
11531174
# Count how many of the burst_N tokens reached the subscriber and check
11541175
# that they arrived in publish order (1, 2, ..., N).
11551176
T26_RECEIVED=$(grep -oE 'burst_[0-9]+' "${TMP_DIR}/t26_sub.log" 2>/dev/null \
1156-
| wc -l)
1177+
| wc -l | tr -d ' ')
11571178
T26_ORDER_OK=yes
11581179
T26_LAST=0
11591180
while read -r tok; do
@@ -1163,11 +1184,18 @@ while read -r tok; do
11631184
fi
11641185
T26_LAST=$n
11651186
done < <(grep -oE 'burst_[0-9]+' "${TMP_DIR}/t26_sub.log" 2>/dev/null)
1166-
if [ "$T26_RECEIVED" = "$T26_N" ] && [ "$T26_ORDER_OK" = "yes" ]; then
1187+
if [ "$T26_RECEIVED" -eq "$T26_N" ] && [ "$T26_ORDER_OK" = "yes" ]; then
11671188
echo "PASS: QoS 1 burst delivery (received=$T26_RECEIVED order=ok)"
11681189
else
11691190
echo "FAIL: Burst delivery (received=$T26_RECEIVED expected=$T26_N " \
11701191
"order=$T26_ORDER_OK)"
1192+
echo "--- t26 broker_log tail ---"
1193+
tail -80 "$broker_log" 2>/dev/null || true
1194+
echo "--- t26_sub.log tail ---"
1195+
tail -40 "${TMP_DIR}/t26_sub.log" 2>/dev/null || true
1196+
echo "--- t26_pub.log tail ---"
1197+
tail -40 "${TMP_DIR}/t26_pub.log" 2>/dev/null || true
1198+
echo "--- t26 end ---"
11711199
FAIL=1
11721200
fi
11731201
fi # skip_plain

0 commit comments

Comments
 (0)