1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//! Result reporting and formatting
use crate::executor::K6Results;
use crate::parallel_executor::AggregatedResults;
use colored::*;
/// Terminal reporter for bench results
pub struct TerminalReporter;
impl TerminalReporter {
/// Print a summary of the bench results.
///
/// `cps_mode` is `true` when the bench was invoked with `--cps`. In that
/// mode each request opens a fresh TCP/TLS connection, so we print an
/// explicit "Connection Rate" line alongside RPS — Srikanth's round-5
/// reply on Issue #79: "CPS without RPS Command is Working but Client
/// dont report CPS Counts".
pub fn print_summary(results: &K6Results, duration_secs: u64) {
Self::print_summary_with_mode(results, duration_secs, false);
}
/// Like [`print_summary`] but lets the caller opt into the `--cps` view.
///
/// Issue #79 round 6 — the connection-count lines now render unconditionally
/// whenever k6 reported `http_req_connecting` samples (i.e. it actually
/// opened TCP sockets), so non-`--cps` runs also surface client-side
/// connection counts. Without `--cps` k6 reuses sockets, so the count
/// equals "distinct connections opened", which is what Srikanth wanted
/// alongside RPS.
pub fn print_summary_with_mode(results: &K6Results, duration_secs: u64, cps_mode: bool) {
println!("\n{}", "=".repeat(60).bright_green());
println!("{}", "Load Test Complete! ✓".bright_green().bold());
println!("{}\n", "=".repeat(60).bright_green());
println!("{}", "Summary:".bold());
println!(" Total Requests: {}", results.total_requests.to_string().cyan());
println!(
" Successful: {} ({}%)",
(results.total_requests - results.failed_requests).to_string().green(),
format!("{:.2}", results.success_rate()).green()
);
println!(
" Failed: {} ({}%)",
results.failed_requests.to_string().red(),
format!("{:.2}", results.error_rate()).red()
);
println!("\n{}", "Response Times:".bold());
println!(" Min: {}ms", format!("{:.2}", results.min_duration_ms).cyan());
println!(" Avg: {}ms", format!("{:.2}", results.avg_duration_ms).cyan());
println!(" Med: {}ms", format!("{:.2}", results.med_duration_ms).cyan());
println!(" p90: {}ms", format!("{:.2}", results.p90_duration_ms).cyan());
println!(" p95: {}ms", format!("{:.2}", results.p95_duration_ms).cyan());
println!(" p99: {}ms", format!("{:.2}", results.p99_duration_ms).cyan());
println!(" Max: {}ms", format!("{:.2}", results.max_duration_ms).cyan());
println!("\n{}", "Throughput:".bold());
if results.rps > 0.0 {
println!(" RPS: {} req/s", format!("{:.1}", results.rps).cyan());
} else {
println!(
" RPS: {} req/s",
format!("{:.1}", results.total_requests as f64 / duration_secs as f64).cyan()
);
}
if results.vus_max > 0 {
println!(" Max VUs: {}", results.vus_max.to_string().cyan());
}
// Issue #79 (round 5) — Connections-per-second report. When the user
// passed `--cps`, k6 ran with `noConnectionReuse: true` so each
// request opened a new TCP/TLS connection. CPS therefore equals the
// request rate; show it explicitly, plus connect/handshake timing.
if cps_mode {
let cps = if results.rps > 0.0 {
results.rps
} else {
results.total_requests as f64 / duration_secs.max(1) as f64
};
println!(" CPS: {} conn/s (--cps)", format!("{:.1}", cps).cyan());
println!(" Total Connections: {}", results.total_requests.to_string().cyan());
}
// Issue #79 round 6 — Always surface client-side connection counts
// when k6 actually opened sockets. Helpful even without `--cps`
// because it lets you compare "k6 opened N connections" against
// the server's `connections_total_opened` and detect whether
// your proxy is keeping the upstream pool warm.
//
// Round 6 follow-up: `tcp_connect_samples` is now sourced from the
// template's `mockforge_connections_opened` Counter (incremented when
// `res.timings.connecting > 0`). That gives an accurate count for
// both `--cps` (≈ total requests) and the pooled-reuse case (≈ vus_max)
// — Srikanth's "Open/Closed Connection Counter not showing for RPS"
// report on Issue #79.
if results.tcp_connect_samples > 0 && !cps_mode {
// Surface the count in non-CPS mode too — Srikanth's "open
// connection on the client" ask.
println!(
" Connections opened: {} ({} conn/s avg)",
results.tcp_connect_samples.to_string().cyan(),
format!("{:.1}", results.tcp_connect_samples as f64 / duration_secs.max(1) as f64)
.cyan(),
);
// Issue #79 round 8 — Srikanth saw 7425 connections opened with
// --vus 5, expecting ~5 (one per VU under pooled reuse). When
// `tcp_connect_samples` is much larger than `vus_max`, the target
// is closing the socket between requests (proxy upstream pool
// disabled, server `Connection: close`, etc). Without --cps,
// ratios > 5× indicate connection reuse isn't happening.
if results.vus_max > 0 {
let reuse_ratio = results.tcp_connect_samples as f64 / results.vus_max as f64;
if reuse_ratio > 5.0 {
println!(
" {}: {:.0}× more sockets opened than concurrent VUs — \
the target is closing connections (proxy pool disabled, \
`Connection: close`, or short upstream idle timeout).",
"Connection reuse NOT detected".yellow().bold(),
reuse_ratio,
);
}
}
}
// Print TCP/TLS timing whenever the avg is non-zero. Don't gate on
// samples count — k6's Trend metric exposes avg/max in summary.json
// but not count, so the count check was always false even when k6
// had real samples. Issue #79 round 6 follow-up.
if results.tcp_connect_avg_ms > 0.0 || results.tcp_connect_max_ms > 0.0 {
println!(
" TCP connect: avg {:.2}ms, max {:.2}ms",
results.tcp_connect_avg_ms, results.tcp_connect_max_ms,
);
}
if results.tls_handshake_avg_ms > 0.0 || results.tls_handshake_max_ms > 0.0 {
println!(
" TLS handshake: avg {:.2}ms, max {:.2}ms",
results.tls_handshake_avg_ms, results.tls_handshake_max_ms,
);
}
// Peak concurrent VUs — the upper bound on simultaneously-open
// connections from the client. For HTTP/1.1 each VU holds at
// most one socket; for HTTP/2 with multiplexing this is the
// bound on streams, not sockets. Surface it as an open-connection
// ceiling so users can sanity-check against the server's
// `connections_open` gauge.
if results.vus_max > 0
&& (cps_mode || results.tcp_connect_samples > 0 || results.tcp_connect_avg_ms > 0.0)
{
println!(
" Peak concurrent VUs: {} (max open conns from client side)",
results.vus_max.to_string().cyan(),
);
}
// Issue #79 — server-injected chaos signals (latency / jitter / faults)
// observed from MockForge response headers. Surfaces the slice of
// total wire time that came from the chaos middleware vs the system
// under test.
if results.server_injected_latency_samples > 0
|| results.server_injected_jitter_samples > 0
|| results.server_reported_faults > 0
{
println!("\n{}", "Server-Injected (chaos):".bold());
if results.server_injected_latency_samples > 0 {
println!(
" Latency samples: {} (avg {:.2}ms, max {:.2}ms)",
results.server_injected_latency_samples.to_string().cyan(),
results.server_injected_latency_avg_ms,
results.server_injected_latency_max_ms,
);
}
if results.server_injected_jitter_samples > 0 {
println!(
" Jitter samples: {} (avg {:.2}ms)",
results.server_injected_jitter_samples.to_string().cyan(),
results.server_injected_jitter_avg_ms,
);
}
if results.server_reported_faults > 0 {
println!(
" Fault-marked resps: {}",
results.server_reported_faults.to_string().cyan(),
);
}
}
println!("\n{}", "=".repeat(60).bright_green());
}
/// Print header information
pub fn print_header(
spec_file: &str,
target: &str,
num_operations: usize,
scenario: &str,
duration_secs: u64,
) {
println!("\n{}\n", "MockForge Bench - Load Testing Mode".bright_green().bold());
println!("{}", "─".repeat(60).bright_black());
println!("{}: {}", "Specification".bold(), spec_file.cyan());
println!("{}: {}", "Target".bold(), target.cyan());
println!("{}: {} endpoints", "Operations".bold(), num_operations.to_string().cyan());
println!("{}: {}", "Scenario".bold(), scenario.cyan());
println!("{}: {}s", "Duration".bold(), duration_secs.to_string().cyan());
println!("{}\n", "─".repeat(60).bright_black());
}
/// Print progress message
pub fn print_progress(message: &str) {
println!("{} {}", "→".bright_green().bold(), message);
}
/// Print error message
pub fn print_error(message: &str) {
eprintln!("{} {}", "✗".bright_red().bold(), message.red());
}
/// Print success message
pub fn print_success(message: &str) {
println!("{} {}", "✓".bright_green().bold(), message.green());
}
/// Print warning message
pub fn print_warning(message: &str) {
println!("{} {}", "⚠".bright_yellow().bold(), message.yellow());
}
/// Print multi-target summary
pub fn print_multi_target_summary(results: &AggregatedResults) {
println!("\n{}", "=".repeat(60).bright_green());
println!("{}", "Multi-Target Load Test Complete! ✓".bright_green().bold());
println!("{}\n", "=".repeat(60).bright_green());
println!("{}", "Overall Summary:".bold());
println!(" Total Targets: {}", results.total_targets.to_string().cyan());
println!(
" Successful: {} ({}%)",
results.successful_targets.to_string().green(),
format!(
"{:.1}",
(results.successful_targets as f64 / results.total_targets as f64) * 100.0
)
.green()
);
println!(
" Failed: {} ({}%)",
results.failed_targets.to_string().red(),
format!(
"{:.1}",
(results.failed_targets as f64 / results.total_targets as f64) * 100.0
)
.red()
);
println!("\n{}", "Aggregated Metrics:".bold());
println!(
" Total Requests: {}",
results.aggregated_metrics.total_requests.to_string().cyan()
);
println!(
" Failed Requests: {} ({}%)",
results.aggregated_metrics.total_failed_requests.to_string().red(),
format!("{:.2}", results.aggregated_metrics.error_rate).red()
);
println!(
" Total RPS: {} req/s",
format!("{:.1}", results.aggregated_metrics.total_rps).cyan()
);
println!(
" Avg RPS/target: {} req/s",
format!("{:.1}", results.aggregated_metrics.avg_rps).cyan()
);
println!(
" Total VUs: {}",
results.aggregated_metrics.total_vus_max.to_string().cyan()
);
println!(
" Avg Response Time: {}ms",
format!("{:.2}", results.aggregated_metrics.avg_duration_ms).cyan()
);
println!(
" p95 Response Time: {}ms",
format!("{:.2}", results.aggregated_metrics.p95_duration_ms).cyan()
);
println!(
" p99 Response Time: {}ms",
format!("{:.2}", results.aggregated_metrics.p99_duration_ms).cyan()
);
// Show per-target summary
let print_target = |result: &crate::parallel_executor::TargetResult| {
let status = if result.success {
"✓".bright_green()
} else {
"✗".bright_red()
};
println!(" {} {}", status, result.target_url.cyan());
if result.success {
println!(
" Requests: {} RPS: {} VUs: {}",
result.results.total_requests.to_string().white(),
format!("{:.1}", result.results.rps).white(),
result.results.vus_max.to_string().white(),
);
println!(
" Latency: min={:.1}ms avg={:.1}ms med={:.1}ms p90={:.1}ms p95={:.1}ms p99={:.1}ms max={:.1}ms",
result.results.min_duration_ms,
result.results.avg_duration_ms,
result.results.med_duration_ms,
result.results.p90_duration_ms,
result.results.p95_duration_ms,
result.results.p99_duration_ms,
result.results.max_duration_ms,
);
}
if let Some(error) = &result.error {
println!(" Error: {}", error.red());
}
};
if results.total_targets <= 20 {
println!("\n{}", "Per-Target Results:".bold());
for result in &results.target_results {
print_target(result);
}
} else {
// Show top 10 and bottom 10
println!("\n{}", "Top 10 Targets (by requests):".bold());
let mut sorted_results = results.target_results.clone();
sorted_results.sort_by_key(|r| r.results.total_requests);
sorted_results.reverse();
for result in sorted_results.iter().take(10) {
print_target(result);
}
println!("\n{}", "Bottom 10 Targets:".bold());
for result in sorted_results.iter().rev().take(10) {
print_target(result);
}
}
println!("\n{}", "=".repeat(60).bright_green());
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_terminal_reporter_creation() {
let _reporter = TerminalReporter;
}
}