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
//! 0.21 D.2: smoke-test the `drain_timeout` setter shape.
//!
//! Pure builder-side tests — they construct `Monitor`s but never
//! call `run_for` / `run_until_*` so the AsyncCapture::open path
//! is never reached (no `CAP_NET_RAW` required to run). The
//! actual drain phase is exercised by the run loop in production
//! and indirectly by the `monitor_lo_dispatch.rs` root-gated
//! tests that hit the live capture path.
#![cfg(all(feature = "tokio", feature = "flow"))]
use std::time::Duration;
use netring::monitor::Monitor;
use netring::protocol::builtin::Tcp;
#[test]
fn drain_timeout_setter_accepts_zero() {
// Zero = skip the drain phase entirely. Useful for fail-fast
// smoke tests that don't care about residual events.
let _m = Monitor::builder()
.interface("lo")
.protocol::<Tcp>()
.drain_timeout(Duration::ZERO)
.build()
.expect("build with zero drain timeout");
}
#[test]
fn drain_timeout_setter_accepts_one_second() {
let _m = Monitor::builder()
.interface("lo")
.protocol::<Tcp>()
.drain_timeout(Duration::from_secs(1))
.build()
.expect("build with 1s drain timeout");
}
#[test]
fn drain_timeout_setter_accepts_large_durations() {
let _m = Monitor::builder()
.interface("lo")
.protocol::<Tcp>()
.drain_timeout(Duration::from_secs(60))
.build()
.expect("build with 60s drain timeout");
}
#[test]
fn drain_timeout_default_is_implicit_when_unset() {
// Build without `.drain_timeout(_)`. The `MonitorBuilder::build`
// path picks the 1s default — this just confirms the build
// path compiles + runs without the setter.
let _m = Monitor::builder()
.interface("lo")
.protocol::<Tcp>()
.build()
.expect("build without drain_timeout setter");
}