test(client): cover TTL and pending expiry without poll coupling

This commit is contained in:
Nils Andreas Svee committed 2026-10-03 00:20:03 +07:00
1 parent d571315068
commit 143d730aa2
3 files changed
+128 -55

No files matched your search

+17 -1
View File
@@ -14,6 +14,8 @@ use irtt_proto::{decode_request, Clock, DecodedRequestKind, ReceivedStats, Stamp
use irtt_server::{ServerConfig, ServerCore};
use nix::sys::socket::{recvmsg, ControlMessageOwned, MsgFlags};
const TEST_TTL: u32 = 37;
// A compliant packet peer uses the real server core. Its receive-side IP_TOS
// observation is independent of the client/server parameter agreement.
fn peer(dscp_allowed: bool, probes: usize) -> (SocketAddr, thread::JoinHandle<Vec<u8>>) {
@@ -24,6 +26,7 @@ fn peer(dscp_allowed: bool, probes: usize) -> (SocketAddr, thread::JoinHandle<Ve
socket2::SockRef::from(&socket)
.set_recv_tos_v4(true)
.unwrap();
nix::sys::socket::setsockopt(&socket, nix::sys::socket::sockopt::Ipv4RecvTtl, &true).unwrap();
let addr = socket.local_addr().unwrap();
let task = thread::spawn(move || {
let mut core = ServerCore::new(
@@ -35,7 +38,7 @@ fn peer(dscp_allowed: bool, probes: usize) -> (SocketAddr, thread::JoinHandle<Ve
// OPEN, every ECHO, then CLOSE.
for _ in 0..probes + 2 {
let mut bytes = [0; 2048];
let mut control = nix::cmsg_space!(u8);
let mut control = nix::cmsg_space!(u8, i32);
let mut iov = [IoSliceMut::new(&mut bytes)];
let msg = recvmsg::<nix::sys::socket::SockaddrIn>(
std::os::fd::AsRawFd::as_raw_fd(&socket),
@@ -54,6 +57,18 @@ fn peer(dscp_allowed: bool, probes: usize) -> (SocketAddr, thread::JoinHandle<Ve
_ => None,
})
.expect("Linux must report IP_TOS");
let ttl = msg
.cmsgs()
.unwrap()
.find_map(|message| match message {
ControlMessageOwned::Ipv4Ttl(ttl) => Some(ttl),
_ => None,
})
.expect("Linux must report IP_TTL");
assert_eq!(
ttl, TEST_TTL as i32,
"configured TTL must survive OPEN, ECHO and CLOSE"
);
markings.push(marking);
let source = SocketAddr::from((source.ip(), source.port()));
if let Some(reply) = core.handle_datagram(source, &bytes[..size]).unwrap() {
@@ -79,6 +94,7 @@ fn config(addr: SocketAddr) -> ClientConfig {
length: 128,
open_timeouts: vec![Duration::from_secs(1)],
socket_config: SocketConfig {
ttl: Some(TEST_TTL),
recv_timeout: Some(Duration::from_secs(1)),
..SocketConfig::default()
},