From 332416bc8fdd185dbc71e16e6524ee9c77348733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Mon, 10 Mar 2025 15:15:28 +0800 Subject: [PATCH] cmb --- stress_test.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stress_test.sh b/stress_test.sh index b175a82..46effd8 100644 --- a/stress_test.sh +++ b/stress_test.sh @@ -46,9 +46,8 @@ if ! command -v jq &> /dev/null; then exit 1 fi -# 定义高精度时间获取函数 get_time() { - local t=$(date +%s%N) + local t=$(gdate +%s%N) echo $((10#${t:0:10} * 1000000000 + 10#${t:10:9})) } @@ -90,14 +89,15 @@ EOF continue fi - # 提取code字段 - api1_code=$(echo "$response_1" | jq -r '.code') - - if [ "$api1_code" != "200" ]; then - echo "接口 1 返回错误:code=$api1_code, 响应=$response_1" | tee -a "$log_file" - ((failure_count++)) - continue - fi + # 提取code字段并检查存在性 + if echo "$response_1" | jq -e '.code | exists' >/dev/null 2>&1; then + api1_code=$(echo "$response_1" | jq -r '.code') + if [ "$api1_code" != "200" ]; then + echo "接口 1 返回错误:code=$api1_code, 响应=$response_1" | tee -a "$log_file" + ((failure_count++)) + continue + fi + fi # 测量接口 2 响应时间 start_time_2=$(get_time)