atomic_bomb_engine/models/
result.rs

1use crate::models::assert_error_stats::AssertErrKey;
2use crate::models::http_error_stats::HttpErrKey;
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct TestResult {
8    pub total_duration: f64,
9    pub success_rate: f64,
10    pub median_response_time: u64,
11    pub response_time_95: u64,
12    pub response_time_99: u64,
13    pub total_requests: i32,
14    pub rps: f64,
15    pub max_response_time: u64,
16    pub min_response_time: u64,
17    pub err_count: i32,
18    pub total_data_kb: f64,
19    pub throughput_per_second_kb: f64,
20    pub http_errors: HashMap<HttpErrKey, u32>,
21    pub timestamp: u128,
22    pub assert_errors: HashMap<(String, String), u32>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct BatchResult {
27    // 运行时间
28    pub total_duration: f64,
29    // 成功率
30    pub success_rate: f64,
31    // 错误率
32    pub error_rate: f64,
33    // 中位响应时间
34    pub median_response_time: u64,
35    // 95位响应时间
36    pub response_time_95: u64,
37    // 99位响应时间
38    pub response_time_99: u64,
39    // 总请求数
40    pub total_requests: u64,
41    // rps
42    pub rps: f64,
43    // 最大响应时间
44    pub max_response_time: u64,
45    // 最小响应时间
46    pub min_response_time: u64,
47    // 错误数量
48    pub err_count: i32,
49    // 总响应数据量(KB)
50    pub total_data_kb: f64,
51    // 每秒响应数据量
52    pub throughput_per_second_kb: f64,
53    // http错误详情
54    pub http_errors: HashMap<HttpErrKey, u32>,
55    // 时间戳
56    pub timestamp: u128,
57    // 断言错误详情
58    pub assert_errors: HashMap<AssertErrKey, u32>,
59    // 总并发数
60    pub total_concurrent_number: i32,
61    // api响应详情
62    pub api_results: Vec<ApiResult>,
63    // 每秒错误数
64    pub errors_per_second: usize,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct ApiResult {
69    pub name: String,
70    pub url: String,
71    pub host: String,
72    pub path: String,
73    pub method: String,
74    pub success_rate: f64,
75    pub error_rate: f64,
76    pub median_response_time: u64,
77    pub response_time_95: u64,
78    pub response_time_99: u64,
79    pub total_requests: u64,
80    pub rps: f64,
81    pub max_response_time: u64,
82    pub min_response_time: u64,
83    pub err_count: i32,
84    pub total_data_kb: f64,
85    pub throughput_per_second_kb: f64,
86    pub concurrent_number: i32,
87}
88
89impl ApiResult {
90    pub fn new() -> Self {
91        Self {
92            name: String::new(),
93            url: String::new(),
94            host: String::new(),
95            path: String::new(),
96            method: String::new(),
97            success_rate: 0.0,
98            error_rate: 0.0,
99            median_response_time: 0,
100            response_time_95: 0,
101            response_time_99: 0,
102            total_requests: 0,
103            rps: 0.0,
104            max_response_time: 0,
105            min_response_time: 0,
106            err_count: 0,
107            total_data_kb: 0.0,
108            throughput_per_second_kb: 0.0,
109            concurrent_number: 0,
110        }
111    }
112}