Skip to content

Commit de09393

Browse files
committed
fix: improve test reliability and code quality
1 parent c8ab113 commit de09393

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/report.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ pub(crate) fn response_metrics_row(metric: ResponseMetric) -> String {
177177
if metric.is_breakdown {
178178
// Status code breakdown row - merge first two columns and use increased indentation
179179
format!(
180-
r#"<tr style="background-color: #f8f9fa;">
181-
<td colspan="2" style="padding-left: 50px; font-style: italic; text-align: left;">{method}</td>
180+
r#"<tr class="status-breakdown">
181+
<td colspan="2">{method}</td>
182182
<td>{percentile_50}</td>
183183
<td>{percentile_60}</td>
184184
<td>{percentile_70}</td>
@@ -653,6 +653,13 @@ pub(crate) fn build_report(
653653
color: #00ca5a;
654654
}}
655655
656+
.status-breakdown {{
657+
background-color: #f8f9fa;
658+
padding-left: 50px;
659+
font-style: italic;
660+
text-align: left;
661+
}}
662+
656663
.graph {{
657664
margin-bottom: 1em;
658665
}}

src/util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ pub fn median(
206206
min: usize,
207207
max: usize,
208208
) -> usize {
209+
// Guard against empty data structures
210+
if total_elements == 0 || btree.is_empty() {
211+
return 0;
212+
}
213+
209214
let mut total_count: usize = 0;
210215
let half_elements: usize = (total_elements as f64 / 2.0).round() as usize;
211216
for (value, counter) in btree {

tests/status_code_response_times.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub async fn get_error(user: &mut GooseUser) -> TransactionResult {
4747

4848
// Set up mock server with different endpoints that return different status codes.
4949
fn setup_mock_server_endpoints(server: &MockServer) -> Vec<Mock<'_>> {
50-
let mut mocks = vec![
50+
let mocks = vec![
5151
// SUCCESS_PATH always returns 200
5252
server.mock(|when, then| {
5353
when.method(GET).path(SUCCESS_PATH);
@@ -65,15 +65,6 @@ fn setup_mock_server_endpoints(server: &MockServer) -> Vec<Mock<'_>> {
6565
}),
6666
];
6767

68-
// Add a separate mock for MIXED_PATH that returns 400 occasionally
69-
// This will be handled randomly by httpmock
70-
for _ in 0..2 {
71-
mocks.push(server.mock(|when, then| {
72-
when.method(GET).path(MIXED_PATH);
73-
then.status(400);
74-
}));
75-
}
76-
7768
mocks
7869
}
7970

@@ -95,7 +86,7 @@ fn validate_status_code_response_times(goose_metrics: &GooseMetrics, mock_endpoi
9586
// Test the /success endpoint - should only have 200 status codes
9687
let success_request = goose_metrics
9788
.requests
98-
.get(&format!("GET {}", SUCCESS_PATH))
89+
.get(&format!("GET {SUCCESS_PATH}"))
9990
.expect("Success request should exist");
10091

10192
// Should have status code counts
@@ -129,7 +120,7 @@ fn validate_status_code_response_times(goose_metrics: &GooseMetrics, mock_endpoi
129120
// Test the /mixed endpoint - should have both 200 and 400 status codes
130121
let mixed_request = goose_metrics
131122
.requests
132-
.get(&format!("GET {}", MIXED_PATH))
123+
.get(&format!("GET {MIXED_PATH}"))
133124
.expect("Mixed request should exist");
134125

135126
// Should have status code counts for both 200 and 400
@@ -151,7 +142,7 @@ fn validate_status_code_response_times(goose_metrics: &GooseMetrics, mock_endpoi
151142
// Test the /error endpoint - should only have 400 status codes
152143
let error_request = goose_metrics
153144
.requests
154-
.get(&format!("GET {}", ERROR_PATH))
145+
.get(&format!("GET {ERROR_PATH}"))
155146
.expect("Error request should exist");
156147

157148
// Should have status code counts

0 commit comments

Comments
 (0)