Skip to content

Commit 2addc3c

Browse files
committed
test(ip_recverr): Change the test files following new method
1 parent 57aa5df commit 2addc3c

File tree

1 file changed

+73
-99
lines changed

1 file changed

+73
-99
lines changed

quinn-udp/tests/tests.rs

Lines changed: 73 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ fn ip_to_v6_mapped(x: IpAddr) -> IpAddr {
373373
#[cfg(target_os = "linux")]
374374
#[test]
375375
fn test_ip_recverr() {
376-
use std::io::IoSliceMut;
377376
use std::time::Duration;
378377

379378
let socket = socket2::Socket::new(
@@ -407,68 +406,76 @@ fn test_ip_recverr() {
407406

408407
std::thread::sleep(Duration::from_millis(200));
409408

410-
let mut buf = [0u8; 1500];
411-
let mut meta = RecvMeta::default();
412-
let mut received_icmp_error = false;
413-
414-
for attempt in 0..5 {
415-
match state.recv(
416-
(&socket).into(),
417-
&mut [IoSliceMut::new(&mut buf)],
418-
std::slice::from_mut(&mut meta),
419-
) {
420-
Ok(n) => {
421-
println!("Attempt {}: Received {} messages", attempt, n);
422-
}
423-
Err(e) => {
424-
println!(
425-
"Attempt {}: Received error: {} (kind: {:?}, raw: {:?})",
426-
attempt,
427-
e,
428-
e.kind(),
429-
e.raw_os_error()
430-
);
431-
432-
// Check if this is an ICMP-related error
433-
match e.raw_os_error() {
434-
Some(libc::EHOSTUNREACH) => {
435-
println!("Received EHOSTUNREACH (Host unreachable)");
436-
received_icmp_error = true;
437-
}
438-
Some(libc::ENETUNREACH) => {
439-
println!("Received ENETUNREACH (Network unreachable)");
440-
received_icmp_error = true;
441-
}
442-
Some(libc::ECONNREFUSED) => {
443-
println!("Received ECONNREFUSED (Connection refused)");
444-
received_icmp_error = true;
445-
}
446-
Some(libc::ETIMEDOUT) => {
447-
println!("Received ETIMEDOUT (Timeout)");
448-
received_icmp_error = true;
449-
}
450-
_ if e.kind() == std::io::ErrorKind::WouldBlock => {
451-
println!("No more errors in queue");
452-
break;
453-
}
454-
_ => {}
455-
}
456-
}
409+
// for attempt in 0..5 {
410+
// match state.recv(
411+
// (&socket).into(),
412+
// &mut [IoSliceMut::new(&mut buf)],
413+
// std::slice::from_mut(&mut meta),
414+
// ) {
415+
// Ok(n) => {
416+
// println!("Attempt {}: Received {} messages", attempt, n);
417+
// }
418+
// Err(e) => {
419+
// println!(
420+
// "Attempt {}: Received error: {} (kind: {:?}, raw: {:?})",
421+
// attempt,
422+
// e,
423+
// e.kind(),
424+
// e.raw_os_error()
425+
// );
426+
427+
// // Check if this is an ICMP-related error
428+
// match e.raw_os_error() {
429+
// Some(libc::EHOSTUNREACH) => {
430+
// println!("Received EHOSTUNREACH (Host unreachable)");
431+
// received_icmp_error = true;
432+
// }
433+
// Some(libc::ENETUNREACH) => {
434+
// println!("Received ENETUNREACH (Network unreachable)");
435+
// received_icmp_error = true;
436+
// }
437+
// Some(libc::ECONNREFUSED) => {
438+
// println!("Received ECONNREFUSED (Connection refused)");
439+
// received_icmp_error = true;
440+
// }
441+
// Some(libc::ETIMEDOUT) => {
442+
// println!("Received ETIMEDOUT (Timeout)");
443+
// received_icmp_error = true;
444+
// }
445+
// _ if e.kind() == std::io::ErrorKind::WouldBlock => {
446+
// println!("No more errors in queue");
447+
// break;
448+
// }
449+
// _ => {}
450+
// }
451+
// }
452+
// }
453+
// std::thread::sleep(Duration::from_millis(10));
454+
// }
455+
456+
// if received_icmp_error {
457+
// println!("IP_RECVERR is working! Received ICMP error.");
458+
// } else {
459+
// println!("No ICMP error received (may be normal depending on network config)");
460+
// }
461+
462+
match state.recv_icmp_err((&socket).into()) {
463+
Ok(Some(icmp_err)) => {
464+
eprintln!("icmp packet recieved");
465+
assert_eq!(unreachable_addr.ip(), icmp_err.addr.ip());
466+
}
467+
Ok(None) => {
468+
eprintln!("No ICMP Recieved");
469+
}
470+
Err(e) => {
471+
eprintln!("Error in reciveing icmp packet: {}", e);
457472
}
458-
std::thread::sleep(Duration::from_millis(10));
459-
}
460-
461-
if received_icmp_error {
462-
println!("IP_RECVERR is working! Received ICMP error.");
463-
} else {
464-
println!("No ICMP error received (may be normal depending on network config)");
465473
}
466474
}
467475

468476
#[cfg(target_os = "linux")]
469477
#[test]
470478
fn test_ipv6_recverr() {
471-
use std::io::IoSliceMut;
472479
use std::time::Duration;
473480

474481
let socket = socket2::Socket::new(
@@ -504,49 +511,16 @@ fn test_ipv6_recverr() {
504511

505512
std::thread::sleep(Duration::from_millis(200));
506513

507-
let mut buf = [0u8; 1500];
508-
let mut meta = RecvMeta::default();
509-
let mut received_icmp_error = false;
510-
511-
for attempt in 0..5 {
512-
match state.recv(
513-
(&socket).into(),
514-
&mut [IoSliceMut::new(&mut buf)],
515-
std::slice::from_mut(&mut meta),
516-
) {
517-
Ok(n) => {
518-
println!("Attempt {}: Received {} messages", attempt, n);
519-
}
520-
Err(e) => {
521-
println!(
522-
"Attempt {}: Error: {} (raw: {:?})",
523-
attempt,
524-
e,
525-
e.raw_os_error()
526-
);
527-
528-
match e.raw_os_error() {
529-
Some(libc::EHOSTUNREACH)
530-
| Some(libc::ENETUNREACH)
531-
| Some(libc::ECONNREFUSED)
532-
| Some(libc::ETIMEDOUT) => {
533-
println!("✓ Received ICMPv6 error");
534-
received_icmp_error = true;
535-
break;
536-
}
537-
_ if e.kind() == std::io::ErrorKind::WouldBlock => {
538-
break;
539-
}
540-
_ => {}
541-
}
542-
}
514+
match state.recv_icmp_err((&socket).into()) {
515+
Ok(Some(icmp_err)) => {
516+
eprintln!("Recived ICMPV6 Packets");
517+
assert_eq!(unreachable_addr.ip(), icmp_err.addr.ip());
518+
}
519+
Ok(None) => {
520+
eprintln!("No ICMPV6 packets are recieved")
521+
}
522+
Err(e) => {
523+
eprintln!("Error in sending ICMP packets: {}", e);
543524
}
544-
std::thread::sleep(Duration::from_millis(10));
545-
}
546-
547-
if received_icmp_error {
548-
println!("IPV6_RECVERR is working!");
549-
} else {
550-
println!("No ICMPv6 error received");
551525
}
552526
}

0 commit comments

Comments
 (0)