Skip to content

Commit ca4515b

Browse files
committed
pass pre-commit
Signed-off-by: Kobe Chen <[email protected]>
1 parent d58f4ca commit ca4515b

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

.github/workflows/router-e2e-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,4 @@ jobs:
289289
echo "🧹 Cleaning up router processes"
290290
pkill -f "python3 -m src.vllm_router.app" || true
291291
292-
- run: echo "🍏 Router stress test job status is ${{ job.status }}."
292+
- run: echo "🍏 Router stress test job status is ${{ job.status }}."

src/vllm_router/services/request_service/request.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,24 @@ async def process_request(
9595
request.app.state.request_stats_monitor.on_new_request(
9696
backend_url, request_id, start_time
9797
)
98-
98+
9999
# Check if stress test mode is enabled; used for tests/e2e/stress-test.sh
100100
if os.getenv("VLLM_ROUTER_STRESS_TEST_MODE", "false").lower() == "true":
101101
# Mock response for stress testing - skip backend calls
102102
mock_headers = {"content-type": "application/json", "x-request-id": request_id}
103103
mock_response = b'{"id":"test","object":"chat.completion","choices":[{"message":{"role":"assistant","content":"Test"},"index":0,"finish_reason":"stop"}]}'
104-
104+
105105
# Yield headers and mock response
106106
yield mock_headers, 200
107-
request.app.state.request_stats_monitor.on_request_response(backend_url, request_id, time.time())
107+
request.app.state.request_stats_monitor.on_request_response(
108+
backend_url, request_id, time.time()
109+
)
108110
yield mock_response
109-
request.app.state.request_stats_monitor.on_request_complete(backend_url, request_id, time.time())
111+
request.app.state.request_stats_monitor.on_request_complete(
112+
backend_url, request_id, time.time()
113+
)
110114
return
111-
115+
112116
# Check if this is a streaming request
113117
is_streaming = False
114118
try:

tests/e2e/router-stress-test.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ cleanup() {
9494
# Function to start router
9595
start_router() {
9696
local log_file="$LOG_DIR/router.log"
97-
97+
9898
print_status "Starting router with round-robin routing (stress test mode)"
99-
99+
100100
# Create log directory
101101
mkdir -p "$(dirname "$log_file")"
102-
102+
103103
# Set stress test mode
104104
export VLLM_ROUTER_STRESS_TEST_MODE=true
105-
105+
106106
# Start router with detailed logging
107107
python3 -m src.vllm_router.app --port "$ROUTER_PORT" \
108108
--service-discovery static \
@@ -112,10 +112,10 @@ start_router() {
112112
--routing-logic roundrobin \
113113
--log-stats \
114114
--log-stats-interval 5 > "$log_file" 2>&1 &
115-
115+
116116
ROUTER_PID=$!
117117
print_status "Router started with PID: $ROUTER_PID"
118-
118+
119119
# Wait for router to be ready
120120
print_status "Waiting for router to be ready..."
121121
timeout 30 bash -c "until curl -s http://localhost:$ROUTER_PORT/v1/models > /dev/null 2>&1; do sleep 1; done" || {
@@ -131,7 +131,7 @@ start_router() {
131131
run_stress_test() {
132132
print_status "Running stress test with Apache Bench"
133133
print_status "Concurrent: $CONCURRENT, Total: $REQUESTS"
134-
134+
135135
# Create payload file
136136
local payload_file="/tmp/stress_payload.json"
137137
cat > "$payload_file" << EOF
@@ -144,7 +144,7 @@ run_stress_test() {
144144
"temperature": 0.7
145145
}
146146
EOF
147-
147+
148148
# Run Apache Bench
149149
ab -c "$CONCURRENT" \
150150
-n "$REQUESTS" \
@@ -153,53 +153,53 @@ EOF
153153
-H "Authorization: Bearer test" \
154154
-H "x-user-id: stress-test-user" \
155155
"http://localhost:$ROUTER_PORT/v1/chat/completions"
156-
156+
157157
# Clean up payload file
158158
rm -f "$payload_file"
159-
159+
160160
print_status "Stress test completed"
161-
161+
162162
# Small delay to ensure all logs are written
163163
sleep 2
164164
}
165165

166166
# Function to check round-robin correctness
167167
check_roundrobin_correctness() {
168168
local log_file="$LOG_DIR/router.log"
169-
169+
170170
print_status "Checking round-robin routing correctness..."
171-
171+
172172
if [ ! -f "$log_file" ]; then
173173
print_error "Router log file not found: $log_file"
174174
return 1
175175
fi
176-
176+
177177
# Extract backend routing decisions from logs
178178
# Look for "Routing request ... to http://localhost:XXXX"
179179
local backend1_count=$(grep -c "to http://localhost:$BACKEND1_PORT" "$log_file" || echo "0")
180180
local backend2_count=$(grep -c "to http://localhost:$BACKEND2_PORT" "$log_file" || echo "0")
181181
local total_routed=$((backend1_count + backend2_count))
182-
182+
183183
print_status "Round-robin routing results:"
184184
print_status " Backend localhost:$BACKEND1_PORT: $backend1_count requests"
185185
print_status " Backend localhost:$BACKEND2_PORT: $backend2_count requests"
186186
print_status " Total routed: $total_routed requests"
187-
187+
188188
if [ "$total_routed" -eq 0 ]; then
189189
print_error "No routing decisions found in logs"
190190
return 1
191191
fi
192-
192+
193193
# Calculate percentages
194194
local backend1_pct=$((backend1_count * 100 / total_routed))
195195
local backend2_pct=$((backend2_count * 100 / total_routed))
196-
196+
197197
print_status " Backend localhost:$BACKEND1_PORT: ${backend1_pct}%"
198198
print_status " Backend localhost:$BACKEND2_PORT: ${backend2_pct}%"
199-
199+
200200
# Check if distribution is roughly even (within 20% tolerance)
201201
local diff=$((backend1_pct > backend2_pct ? backend1_pct - backend2_pct : backend2_pct - backend1_pct))
202-
202+
203203
if [ "$diff" -le 20 ]; then
204204
print_status "✅ Round-robin routing is working correctly (${diff}% difference)"
205205
return 0
@@ -214,7 +214,7 @@ check_roundrobin_correctness() {
214214
# Function to show log summary
215215
show_log_summary() {
216216
local log_file="$LOG_DIR/router.log"
217-
217+
218218
if [ -f "$log_file" ]; then
219219
print_status "Log summary (last 20 lines):"
220220
tail -20 "$log_file" | sed 's/^/ /'
@@ -292,4 +292,4 @@ else
292292
print_error "Test completed but round-robin routing correctness check failed!"
293293
show_log_summary
294294
exit 1
295-
fi
295+
fi

0 commit comments

Comments
 (0)