|
| 1 | + |
| 2 | +# Shared helpers for --json-file result assertions (POSIX sh) |
| 3 | + |
| 4 | +JSON_OUT_DIR="${RUN_DIR}/.json-out" |
| 5 | +mkdir -p "${JSON_OUT_DIR}" |
| 6 | + |
| 7 | +assert_json_eq() |
| 8 | +{ |
| 9 | + _aj_eq_file=$1 |
| 10 | + _aj_eq_expr=$2 |
| 11 | + _aj_eq_expected=$3 |
| 12 | + _aj_eq_actual=$(jq -er "${_aj_eq_expr}" "${_aj_eq_file}") |
| 13 | + if [ "${_aj_eq_actual}" != "${_aj_eq_expected}" ]; then |
| 14 | + echo "JSON assert failed for ${_aj_eq_file}: ${_aj_eq_expr} expected='${_aj_eq_expected}' actual='${_aj_eq_actual}'" >&2 |
| 15 | + exit 1 |
| 16 | + fi |
| 17 | +} |
| 18 | + |
| 19 | +assert_json_gt() |
| 20 | +{ |
| 21 | + _aj_gt_file=$1 |
| 22 | + _aj_gt_expr=$2 |
| 23 | + _aj_gt_min=$3 |
| 24 | + _aj_gt_actual=$(jq -er "${_aj_gt_expr}" "${_aj_gt_file}") |
| 25 | + if ! [ "${_aj_gt_actual}" -gt "${_aj_gt_min}" ]; then |
| 26 | + echo "JSON assert failed for ${_aj_gt_file}: ${_aj_gt_expr} expected > ${_aj_gt_min} actual='${_aj_gt_actual}'" >&2 |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +assert_json_type() |
| 32 | +{ |
| 33 | + _aj_ty_file=$1 |
| 34 | + _aj_ty_expr=$2 |
| 35 | + _aj_ty_type=$3 |
| 36 | + _aj_ty_actual=$(jq -er "${_aj_ty_expr} | type" "${_aj_ty_file}") |
| 37 | + if [ "${_aj_ty_actual}" != "${_aj_ty_type}" ]; then |
| 38 | + echo "JSON assert failed for ${_aj_ty_file}: ${_aj_ty_expr} type expected='${_aj_ty_type}' actual='${_aj_ty_actual}'" >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +assert_json_null() |
| 44 | +{ |
| 45 | + _aj_nu_file=$1 |
| 46 | + _aj_nu_expr=$2 |
| 47 | + _aj_nu_actual=$(jq -er "${_aj_nu_expr} | type" "${_aj_nu_file}") |
| 48 | + if [ "${_aj_nu_actual}" != "null" ]; then |
| 49 | + echo "JSON assert failed for ${_aj_nu_file}: ${_aj_nu_expr} expected null actual type='${_aj_nu_actual}'" >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +} |
| 53 | + |
| 54 | +assert_hist_snapshot() |
| 55 | +{ |
| 56 | + _aj_hs_file=$1 |
| 57 | + _aj_hs_expr=$2 |
| 58 | + assert_json_type "${_aj_hs_file}" "${_aj_hs_expr}.min" number |
| 59 | + assert_json_type "${_aj_hs_file}" "${_aj_hs_expr}.mean" number |
| 60 | + assert_json_type "${_aj_hs_file}" "${_aj_hs_expr}.stdev" number |
| 61 | + assert_json_type "${_aj_hs_file}" "${_aj_hs_expr}.p90" number |
| 62 | + assert_json_type "${_aj_hs_file}" "${_aj_hs_expr}.max" number |
| 63 | +} |
| 64 | + |
| 65 | +assert_json_report() |
| 66 | +{ |
| 67 | + # assert_json_report <file> <target> <concurrency> <complete_requests> |
| 68 | + _aj_rp_file=$1 |
| 69 | + _aj_rp_target=$2 |
| 70 | + _aj_rp_concurrency=$3 |
| 71 | + _aj_rp_complete=$4 |
| 72 | + assert_json_eq "${_aj_rp_file}" .version 1 |
| 73 | + assert_json_eq "${_aj_rp_file}" .target "${_aj_rp_target}" |
| 74 | + assert_json_eq "${_aj_rp_file}" .concurrency "${_aj_rp_concurrency}" |
| 75 | + assert_json_eq "${_aj_rp_file}" .global.complete_requests "${_aj_rp_complete}" |
| 76 | + assert_json_eq "${_aj_rp_file}" .global.failed_requests 0 |
| 77 | + assert_json_gt "${_aj_rp_file}" .global.total_time_ns 0 |
| 78 | + assert_json_type "${_aj_rp_file}" .global.requests_per_sec number |
| 79 | + assert_json_type "${_aj_rp_file}" .histograms object |
| 80 | + assert_hist_snapshot "${_aj_rp_file}" .histograms.durations_ns.total |
| 81 | + assert_json_type "${_aj_rp_file}" .percentiles_ns.p50 number |
| 82 | + assert_json_type "${_aj_rp_file}" .percentiles_ns.p100 number |
| 83 | +} |
| 84 | + |
| 85 | +assert_json_tcp_traffic() |
| 86 | +{ |
| 87 | + _aj_tcp_file=$1 |
| 88 | + assert_json_type "${_aj_tcp_file}" .traffic.tcp object |
| 89 | + assert_json_gt "${_aj_tcp_file}" .traffic.tcp.send_bytes 0 |
| 90 | + assert_json_gt "${_aj_tcp_file}" .traffic.tcp.recv_bytes 0 |
| 91 | + assert_json_null "${_aj_tcp_file}" .traffic.udp |
| 92 | +} |
| 93 | + |
| 94 | +assert_json_udp_traffic() |
| 95 | +{ |
| 96 | + _aj_udp_file=$1 |
| 97 | + assert_json_type "${_aj_udp_file}" .traffic.udp object |
| 98 | + assert_json_gt "${_aj_udp_file}" .traffic.udp.send_bytes 0 |
| 99 | + assert_json_gt "${_aj_udp_file}" .traffic.udp.send_packets 0 |
| 100 | + assert_json_gt "${_aj_udp_file}" .traffic.udp.recv_packets 0 |
| 101 | + assert_json_null "${_aj_udp_file}" .traffic.tcp |
| 102 | +} |
| 103 | + |
| 104 | +assert_json_http_histograms() |
| 105 | +{ |
| 106 | + _aj_hh_file=$1 |
| 107 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.conn_used_times |
| 108 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.durations_ns.connect |
| 109 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.durations_ns.send_hdr |
| 110 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.durations_ns.send_all |
| 111 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.durations_ns.recv_hdr |
| 112 | + assert_hist_snapshot "${_aj_hh_file}" .histograms.durations_ns.total |
| 113 | +} |
0 commit comments