Skip to content

Commit ae1cbd9

Browse files
committed
fix: resolve ShellCheck SC2155 warnings in stress-test.sh
Separate variable declarations from assignments to avoid masking return values in backend count extraction logic. Signed-off-by: YuhanLiu11 <[email protected]>
1 parent 194eaf1 commit ae1cbd9

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

tests/e2e/stress-test.sh

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ cleanup() {
170170
# Function to start router
171171
start_router() {
172172
local log_file="$LOG_DIR/router.log"
173-
173+
174174
print_status "Starting router with round-robin routing (stress test mode)"
175-
175+
176176
# Create log directory
177177
mkdir -p "$(dirname "$log_file")"
178-
178+
179179
# Set stress test mode
180180
export VLLM_ROUTER_STRESS_TEST_MODE=true
181-
181+
182182
# Start router with detailed logging
183183
python3 -m src.vllm_router.app --port "$ROUTER_PORT" \
184184
--service-discovery static \
@@ -188,10 +188,10 @@ start_router() {
188188
--routing-logic roundrobin \
189189
--log-stats \
190190
--log-stats-interval 5 > "$log_file" 2>&1 &
191-
191+
192192
ROUTER_PID=$!
193193
print_status "Router started with PID: $ROUTER_PID"
194-
194+
195195
# Wait for router to be ready
196196
print_status "Waiting for router to be ready..."
197197
timeout 30 bash -c "until curl -s http://localhost:$ROUTER_PORT/v1/models > /dev/null 2>&1; do sleep 1; done" || {
@@ -207,7 +207,7 @@ start_router() {
207207
run_stress_test() {
208208
print_status "Running stress test with Apache Bench"
209209
print_status "Concurrent: $CONCURRENT, Total: $REQUESTS"
210-
210+
211211
# Create payload file
212212
local payload_file="/tmp/stress_payload.json"
213213
cat > "$payload_file" << EOF
@@ -220,7 +220,7 @@ run_stress_test() {
220220
"temperature": 0.7
221221
}
222222
EOF
223-
223+
224224
# Run Apache Bench
225225
ab -c "$CONCURRENT" \
226226
-n "$REQUESTS" \
@@ -229,53 +229,55 @@ EOF
229229
-H "Authorization: Bearer test" \
230230
-H "x-user-id: stress-test-user" \
231231
"http://localhost:$ROUTER_PORT/v1/chat/completions"
232-
232+
233233
# Clean up payload file
234234
rm -f "$payload_file"
235-
235+
236236
print_status "Stress test completed"
237-
237+
238238
# Small delay to ensure all logs are written
239239
sleep 2
240240
}
241241

242242
# Function to check round-robin correctness
243243
check_roundrobin_correctness() {
244244
local log_file="$LOG_DIR/router.log"
245-
245+
246246
print_status "Checking round-robin routing correctness..."
247-
247+
248248
if [ ! -f "$log_file" ]; then
249249
print_error "Router log file not found: $log_file"
250250
return 1
251251
fi
252-
252+
253253
# Extract backend routing decisions from logs
254254
# Look for "Routing request ... to http://localhost:XXXX"
255-
local backend1_count=$(grep -c "to http://localhost:$BACKEND1_PORT" "$log_file" || echo "0")
256-
local backend2_count=$(grep -c "to http://localhost:$BACKEND2_PORT" "$log_file" || echo "0")
255+
local backend1_count
256+
backend1_count=$(grep -c "to http://localhost:$BACKEND1_PORT" "$log_file" || echo "0")
257+
local backend2_count
258+
backend2_count=$(grep -c "to http://localhost:$BACKEND2_PORT" "$log_file" || echo "0")
257259
local total_routed=$((backend1_count + backend2_count))
258-
260+
259261
print_status "Round-robin routing results:"
260262
print_status " Backend localhost:$BACKEND1_PORT: $backend1_count requests"
261263
print_status " Backend localhost:$BACKEND2_PORT: $backend2_count requests"
262264
print_status " Total routed: $total_routed requests"
263-
265+
264266
if [ "$total_routed" -eq 0 ]; then
265267
print_error "No routing decisions found in logs"
266268
return 1
267269
fi
268-
270+
269271
# Calculate percentages
270272
local backend1_pct=$((backend1_count * 100 / total_routed))
271273
local backend2_pct=$((backend2_count * 100 / total_routed))
272-
274+
273275
print_status " Backend localhost:$BACKEND1_PORT: ${backend1_pct}%"
274276
print_status " Backend localhost:$BACKEND2_PORT: ${backend2_pct}%"
275-
277+
276278
# Check if distribution is roughly even (within 20% tolerance)
277279
local diff=$((backend1_pct > backend2_pct ? backend1_pct - backend2_pct : backend2_pct - backend1_pct))
278-
280+
279281
if [ "$diff" -le 20 ]; then
280282
print_status "✅ Round-robin routing is working correctly (${diff}% difference)"
281283
return 0
@@ -290,7 +292,7 @@ check_roundrobin_correctness() {
290292
# Function to show log summary
291293
show_log_summary() {
292294
local log_file="$LOG_DIR/router.log"
293-
295+
294296
if [ -f "$log_file" ]; then
295297
print_status "Log summary (last 20 lines):"
296298
tail -20 "$log_file" | sed 's/^/ /'
@@ -368,4 +370,4 @@ else
368370
print_error "Test completed but round-robin routing correctness check failed!"
369371
show_log_summary
370372
exit 1
371-
fi
373+
fi

0 commit comments

Comments
 (0)