From b0c83921be011d23299a38c936311336a00737f5 Mon Sep 17 00:00:00 2001 From: sakridge Date: Tue, 24 Mar 2020 11:39:36 -0700 Subject: [PATCH] Move streamer test to integration test (#9050) Failing in the coverage build. --- streamer/src/recvmmsg.rs | 45 ---------------------------------- streamer/tests/recvmmsg.rs | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 streamer/tests/recvmmsg.rs diff --git a/streamer/src/recvmmsg.rs b/streamer/src/recvmmsg.rs index 9939c3fe9f..520003413e 100644 --- a/streamer/src/recvmmsg.rs +++ b/streamer/src/recvmmsg.rs @@ -213,49 +213,4 @@ mod tests { assert_eq!(packets[i].meta.addr(), saddr2); } } - - #[cfg(target_os = "linux")] - #[test] - pub fn test_recv_mmsg_batch_size() { - let reader = UdpSocket::bind("127.0.0.1:0").expect("bind"); - let addr = reader.local_addr().unwrap(); - let sender = UdpSocket::bind("127.0.0.1:0").expect("bind"); - - const TEST_BATCH_SIZE: usize = 64; - let sent = TEST_BATCH_SIZE; - - let mut elapsed_in_max_batch = 0; - (0..1000).for_each(|_| { - for _ in 0..sent { - let data = [0; PACKET_DATA_SIZE]; - sender.send_to(&data[..], &addr).unwrap(); - } - let mut packets = vec![Packet::default(); TEST_BATCH_SIZE]; - let now = Instant::now(); - let recv = recv_mmsg(&reader, &mut packets[..]).unwrap().1; - elapsed_in_max_batch += now.elapsed().as_nanos(); - assert_eq!(TEST_BATCH_SIZE, recv); - }); - - let mut elapsed_in_small_batch = 0; - (0..1000).for_each(|_| { - for _ in 0..sent { - let data = [0; PACKET_DATA_SIZE]; - sender.send_to(&data[..], &addr).unwrap(); - } - let mut packets = vec![Packet::default(); 4]; - let mut recv = 0; - let now = Instant::now(); - while let Ok(num) = recv_mmsg(&reader, &mut packets[..]) { - recv += num.1; - if recv >= TEST_BATCH_SIZE { - break; - } - } - elapsed_in_small_batch += now.elapsed().as_nanos(); - assert_eq!(TEST_BATCH_SIZE, recv); - }); - - assert!(elapsed_in_max_batch <= elapsed_in_small_batch); - } } diff --git a/streamer/tests/recvmmsg.rs b/streamer/tests/recvmmsg.rs new file mode 100644 index 0000000000..38d0921196 --- /dev/null +++ b/streamer/tests/recvmmsg.rs @@ -0,0 +1,50 @@ +use solana_streamer::packet::Packet; +use solana_streamer::packet::PACKET_DATA_SIZE; +use solana_streamer::recvmmsg::*; +use std::net::UdpSocket; +use std::time::Instant; + +#[cfg(target_os = "linux")] +#[test] +pub fn test_recv_mmsg_batch_size() { + let reader = UdpSocket::bind("127.0.0.1:0").expect("bind"); + let addr = reader.local_addr().unwrap(); + let sender = UdpSocket::bind("127.0.0.1:0").expect("bind"); + + const TEST_BATCH_SIZE: usize = 64; + let sent = TEST_BATCH_SIZE; + + let mut elapsed_in_max_batch = 0; + (0..1000).for_each(|_| { + for _ in 0..sent { + let data = [0; PACKET_DATA_SIZE]; + sender.send_to(&data[..], &addr).unwrap(); + } + let mut packets = vec![Packet::default(); TEST_BATCH_SIZE]; + let now = Instant::now(); + let recv = recv_mmsg(&reader, &mut packets[..]).unwrap().1; + elapsed_in_max_batch += now.elapsed().as_nanos(); + assert_eq!(TEST_BATCH_SIZE, recv); + }); + + let mut elapsed_in_small_batch = 0; + (0..1000).for_each(|_| { + for _ in 0..sent { + let data = [0; PACKET_DATA_SIZE]; + sender.send_to(&data[..], &addr).unwrap(); + } + let mut packets = vec![Packet::default(); 4]; + let mut recv = 0; + let now = Instant::now(); + while let Ok(num) = recv_mmsg(&reader, &mut packets[..]) { + recv += num.1; + if recv >= TEST_BATCH_SIZE { + break; + } + } + elapsed_in_small_batch += now.elapsed().as_nanos(); + assert_eq!(TEST_BATCH_SIZE, recv); + }); + + assert!(elapsed_in_max_batch <= elapsed_in_small_batch); +}