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
//! Integration tests for capture statistics.
#![cfg(feature = "integration-tests")]
mod helpers;
use netring::Capture;
use std::time::Duration;
#[test]
fn capture_stats_basic() {
let port = helpers::unique_port();
let mut cap = Capture::builder()
.interface(helpers::LOOPBACK)
.block_timeout_ms(10)
.build()
.expect("build capture");
// Reset counters
let _ = cap.stats();
// Send packets
helpers::send_udp_to_loopback(port, b"stats_test_payload", 50);
// Give time for packets to arrive
std::thread::sleep(Duration::from_millis(100));
// Drain some packets to ensure the ring processes them
for _ in 0..10 {
if cap
.next_batch_blocking(Duration::from_millis(50))
.unwrap()
.is_some()
{
break;
}
}
let stats = cap.stats().expect("get stats");
// We should have received at least some packets (loopback has other traffic too)
// The exact count depends on timing, so just verify the field is populated.
assert_eq!(
stats.drops, 0,
"no drops expected on loopback with default ring"
);
}