Skip to content

Commit 1dd6c57

Browse files
committed
Fix HEAD / returning 405 and add port auto-increment test (#15)
The CI setup action health check uses `curl -sf -I` (HEAD request) to verify spiceio is ready. HEAD on the root path returned 405 MethodNotAllowed, and curl's -f flag suppresses output on 4xx errors, causing the Server header grep to find nothing and the 30s timeout loop to expire. - Handle HEAD at root path alongside GET (ListBuckets) - Add port auto-increment integration test: starts a second instance on the same bind address, verifies it auto-increments, and confirms both instances serve S3 requests
1 parent 3fce49d commit 1dd6c57

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

scripts/test-sccache.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ FAIL=0
2525
# ── Cleanup on exit ─────────────────────────────────────────────────────────
2626

2727
SPICEIO_PID=""
28+
SPICEIO_PID2=""
2829
cleanup() {
2930
echo ""
3031
echo "[test] cleaning up..."
3132
sccache --stop-server 2>/dev/null || true
3233
# Remove test objects
3334
$AWS s3 rm "s3://${BUCKET}/${TEST_PREFIX}/" --recursive 2>/dev/null || true
35+
if [[ -n "$SPICEIO_PID2" ]]; then
36+
kill "$SPICEIO_PID2" 2>/dev/null || true
37+
wait "$SPICEIO_PID2" 2>/dev/null || true
38+
fi
3439
if [[ -n "$SPICEIO_PID" ]]; then
3540
kill "$SPICEIO_PID" 2>/dev/null || true
3641
wait "$SPICEIO_PID" 2>/dev/null || true
@@ -237,6 +242,89 @@ if [[ "$FAIL" -gt 0 ]]; then
237242
exit 1
238243
fi
239244

245+
# ════════════════════════════════════════════════════════════════════════════
246+
# Port auto-increment test
247+
# ════════════════════════════════════════════════════════════════════════════
248+
249+
echo ""
250+
echo "======================================="
251+
echo "[test] port auto-increment test"
252+
echo "======================================="
253+
254+
# Start a second instance requesting the same bind address.
255+
# It should auto-increment to the next port.
256+
SPICEIO_LOG2=$(mktemp /tmp/spiceio-test-log2.XXXXXX)
257+
258+
SPICEIO_BIND="$BIND" \
259+
SPICEIO_SMB_SERVER="$SMB_SERVER" \
260+
SPICEIO_SMB_PORT="$SMB_PORT" \
261+
SPICEIO_SMB_USER="$SPICEIO_SMB_USER" \
262+
SPICEIO_SMB_PASS="$SPICEIO_SMB_PASS" \
263+
SPICEIO_SMB_DOMAIN="$SMB_DOMAIN" \
264+
SPICEIO_SMB_SHARE="$SMB_SHARE" \
265+
SPICEIO_BUCKET="$BUCKET" \
266+
SPICEIO_REGION="$REGION" \
267+
SPICEIO_LOG_FILE="$SPICEIO_LOG2" \
268+
"$SPICEIO_BIN" &
269+
SPICEIO_PID2=$!
270+
271+
echo "[test] waiting for second spiceio instance..."
272+
ENDPOINT2=""
273+
for i in $(seq 1 30); do
274+
ENDPOINT2=$(grep 'listening on' "$SPICEIO_LOG2" 2>/dev/null | grep -o 'http://[^ ]*' | tail -1 || true)
275+
if [[ -n "$ENDPOINT2" ]] && curl -sf -o /dev/null "${ENDPOINT2}/" 2>/dev/null; then
276+
break
277+
fi
278+
if ! kill -0 "$SPICEIO_PID2" 2>/dev/null; then
279+
echo " FAIL: second spiceio exited unexpectedly"
280+
FAIL=$((FAIL + 1))
281+
SPICEIO_PID2=""
282+
break
283+
fi
284+
sleep 0.5
285+
done
286+
287+
if [[ -n "$ENDPOINT2" ]]; then
288+
echo "[test] second instance at $ENDPOINT2"
289+
290+
PORT1="${BIND##*:}"
291+
PORT2="${ENDPOINT2##*:}"
292+
assert_eq "port auto-incremented" "$((PORT1 + 1))" "$PORT2"
293+
294+
# Both instances should serve requests
295+
assert_ok "first instance health check" curl -sf -o /dev/null "${ENDPOINT}/"
296+
assert_ok "second instance health check" curl -sf -o /dev/null "${ENDPOINT2}/"
297+
298+
# Both should serve S3 operations (same SMB share)
299+
GOT1=$($AWS s3 cp "s3://${BUCKET}/${TEST_PREFIX}/small.txt" - 2>/dev/null || echo "FAIL")
300+
assert_eq "first instance S3 read" "version2" "$GOT1"
301+
302+
AWS2="aws --endpoint-url $ENDPOINT2 --no-sign-request"
303+
GOT2=$($AWS2 s3 cp "s3://${BUCKET}/${TEST_PREFIX}/small.txt" - 2>/dev/null || echo "FAIL")
304+
assert_eq "second instance S3 read" "version2" "$GOT2"
305+
else
306+
echo " FAIL: second instance did not start"
307+
FAIL=$((FAIL + 1))
308+
fi
309+
310+
# Stop the second instance
311+
if [[ -n "$SPICEIO_PID2" ]]; then
312+
kill "$SPICEIO_PID2" 2>/dev/null || true
313+
wait "$SPICEIO_PID2" 2>/dev/null || true
314+
SPICEIO_PID2=""
315+
fi
316+
rm -f "$SPICEIO_LOG2"
317+
318+
echo ""
319+
echo "======================================="
320+
echo "[test] port auto-increment: $PASS passed, $FAIL failed"
321+
echo "======================================="
322+
323+
if [[ "$FAIL" -gt 0 ]]; then
324+
echo "[test] ABORTING — port auto-increment test failed"
325+
exit 1
326+
fi
327+
240328
# ════════════════════════════════════════════════════════════════════════════
241329
# sccache integration test
242330
# ════════════════════════════════════════════════════════════════════════════

src/s3/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn handle_request(req: Request<Incoming>, state: &AppState) -> Respons
5555
// Service-level operations (no bucket)
5656
if req_bucket.is_empty() {
5757
match method {
58-
Method::GET => {
58+
Method::GET | Method::HEAD => {
5959
return with_common_headers(
6060
list_buckets_response(&state.bucket),
6161
&request_id,

0 commit comments

Comments
 (0)