Skip to content

Commit 8208d1a

Browse files
committed
Add prefix cache test to github actions
1 parent 664e4d4 commit 8208d1a

File tree

4 files changed

+411
-16
lines changed

4 files changed

+411
-16
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# -----------------------------------------------------------------------------
5+
# e2e-validate.sh — CI e2e Gateway smoke-test (chat + completion, 7 iterations)
6+
# By default we only test completion curls unless specifed to run chat.
7+
# -----------------------------------------------------------------------------
8+
9+
show_help() {
10+
cat <<EOF
11+
Usage: $(basename "$0") [OPTIONS]
12+
13+
Options:
14+
-n, --namespace NAMESPACE Kubernetes namespace (default: llm-d)
15+
-m, --model MODEL_ID Model to query.
16+
-c, --chatValidation Enable chat validation testing.
17+
-v, --verbose Echo kubectl/curl commands before running
18+
-h, --help Show this help and exit
19+
EOF
20+
exit 0
21+
}
22+
23+
# ── Defaults ────────────────────────────────────────────────────────────────
24+
NAMESPACE="igw-e2e"
25+
CLI_MODEL_ID=""
26+
VERBOSE=false
27+
TEST_CHAT=false
28+
29+
# ── Flag parsing ────────────────────────────────────────────────────────────
30+
while [[ $# -gt 0 ]]; do
31+
case $1 in
32+
-n|--namespace)
33+
if [[ -z "$2" ]]; then echo "Error: $1 requires a value." >&2; exit 1; fi
34+
NAMESPACE="$2"; shift 2 ;;
35+
-m|--model)
36+
if [[ -z "$2" ]]; then echo "Error: $1 requires a value." >&2; exit 1; fi
37+
CLI_MODEL_ID="$2"; shift 2 ;;
38+
-c|--chatValidation) TEST_CHAT=true; shift ;;
39+
-v|--verbose) VERBOSE=true; shift ;;
40+
-h|--help) show_help ;;
41+
*) echo "Unknown option: $1"; show_help ;;
42+
esac
43+
done
44+
45+
if [[ "${VERBOSE}" == "true" ]]; then
46+
set -x
47+
fi
48+
49+
# ── Create a unique pod suffix ────────────────────────────────────────────
50+
gen_id() { echo $(( RANDOM % 10000 + 1 )); }
51+
52+
# ── Discover Gateway address ────────────────────────────────────────────────
53+
HOST="${GATEWAY_HOST:-$(kubectl get gateway -n "$NAMESPACE" \
54+
-o jsonpath='{.items[0].status.addresses[0].value}' 2>/dev/null || true)}"
55+
if [[ -z "$HOST" ]]; then
56+
echo "Error: could not discover a Gateway address in namespace '$NAMESPACE'." >&2
57+
exit 1
58+
fi
59+
PORT=80
60+
SVC_HOST="${HOST}:${PORT}"
61+
62+
# ── Determine MODEL_ID ──────────────────────────────────────────────────────
63+
if [[ -n "$CLI_MODEL_ID" ]]; then
64+
MODEL_ID="$CLI_MODEL_ID"
65+
elif [[ -n "${MODEL_ID-}" ]]; then
66+
MODEL_ID="$MODEL_ID"
67+
else
68+
echo "Error: Failed to find model id. Please specify one using the -m flag or the MODEL_ID environment variable." >&2
69+
exit 1
70+
fi
71+
72+
echo "Namespace: $NAMESPACE"
73+
echo "Inference Gateway: ${SVC_HOST}"
74+
echo "Model ID: $MODEL_ID"
75+
echo
76+
77+
# ── Main test loop (10 iterations) ──────────────────────────────────────────
78+
for i in {1..7}; do
79+
echo "=== Iteration $i of 10 ==="
80+
failed=false
81+
82+
if [[ -n "$TEST_CHAT" ]]; then
83+
84+
# POST /v1/chat/completions
85+
echo "1) POST /v1/chat/completions at ${SVC_HOST}"
86+
chat_payload='{
87+
"model":"'"$MODEL_ID"'",
88+
"messages":[{"role":"user","content":"Hello! Who are you?"}]
89+
}'
90+
ID=$(gen_id)
91+
92+
ret=0
93+
output=$(kubectl run --rm -i curl-"$ID" \
94+
--namespace "$NAMESPACE" \
95+
--image=curlimages/curl --restart=Never \
96+
--env "PAYLOAD=$chat_payload" -- \
97+
sh -c 'sleep 1; curl -sS -X POST "http://'${SVC_HOST}'/v1/chat/completions" \
98+
-H "accept: application/json" \
99+
-H "Content-Type: application/json" \
100+
-d "$PAYLOAD"') || ret=$?
101+
echo "$output"
102+
[[ $ret -ne 0 || "$output" != *'{'* ]] && {
103+
echo "Error: POST /v1/chat/completions failed (exit $ret or no JSON)" >&2; failed=true; }
104+
echo
105+
fi
106+
107+
# POST /v1/completions
108+
echo "2) POST /v1/completions at ${SVC_HOST}"
109+
payload='{"model":"'"$MODEL_ID"'","prompt":"You are a helpful AI assistant."}'
110+
ID=$(gen_id)
111+
112+
ret=0
113+
output=$(kubectl run --rm -i curl-"$ID" \
114+
--namespace "$NAMESPACE" \
115+
--image=curlimages/curl --restart=Never \
116+
--env "PAYLOAD=$payload" -- \
117+
sh -c 'sleep 1; curl -sS -X POST "http://'${SVC_HOST}'/v1/completions" \
118+
-H "accept: application/json" \
119+
-H "Content-Type: application/json" \
120+
-d "$PAYLOAD"') || ret=$?
121+
echo "$output"
122+
[[ $ret -ne 0 || "$output" != *'{'* ]] && {
123+
echo "Error: POST /v1/completions failed (exit $ret or no JSON)" >&2; failed=true; }
124+
echo
125+
126+
if $failed; then
127+
echo "Iteration $i encountered errors; exiting." >&2
128+
exit 1
129+
fi
130+
done
131+
132+
echo "✅ All 10 iterations succeeded."

0 commit comments

Comments
 (0)