From 75ef0f0329c0397d2f5051c1eee01a5bce89baac Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Wed, 14 Mar 2018 11:02:38 -0700 Subject: [PATCH 1/3] fix test --- src/streamer.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/streamer.rs b/src/streamer.rs index 48d8db74cf8833..6993a26964f982 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -1,5 +1,6 @@ use std::sync::{Arc, Mutex, RwLock}; use std::sync::mpsc; +use std::fmt; use std::time::Duration; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket}; use std::thread::{spawn, JoinHandle}; @@ -16,7 +17,11 @@ pub struct Packet { pub port: u16, pub v6: bool, } - +impl fmt::Debug for Packet { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Packet {{ size: {:?}, addr: {:?} }}", self.size, self.get_addr()) + } +} impl Default for Packet { fn default() -> Packet { Packet { @@ -72,6 +77,7 @@ impl Packet { } } +#[derive(Clone, Debug)] pub struct PacketData { pub packets: Vec, } @@ -292,11 +298,11 @@ mod test { } fn get_msgs(r: Receiver, num: &mut usize) { - for _ in [0..5].iter() { + for _t in 0..5 { let timer = Duration::new(1, 0); match r.recv_timeout(timer) { Ok(m) => *num += m.read().unwrap().packets.len(), - _ => (), + e => println!("error {:?}", e), } if *num == 10 { break; From baa4ea3cd80392ec2011090521f13ddef2234cba Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Wed, 14 Mar 2018 11:14:40 -0700 Subject: [PATCH 2/3] wfmt --- src/streamer.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/streamer.rs b/src/streamer.rs index 6993a26964f982..f761d19516b392 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -19,7 +19,12 @@ pub struct Packet { } impl fmt::Debug for Packet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Packet {{ size: {:?}, addr: {:?} }}", self.size, self.get_addr()) + write!( + f, + "Packet {{ size: {:?}, addr: {:?} }}", + self.size, + self.get_addr() + ) } } impl Default for Packet { From e8faf6d59a50ab284125a50dff6327fd5b18b831 Mon Sep 17 00:00:00 2001 From: Anatoly Yakovenko Date: Wed, 14 Mar 2018 11:28:05 -0700 Subject: [PATCH 3/3] trait test --- src/streamer.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/streamer.rs b/src/streamer.rs index f761d19516b392..c23fdb5ec5d23a 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -224,6 +224,8 @@ mod test { use std::thread::{spawn, JoinHandle}; use std::sync::mpsc::channel; use result::Result; + use std::io::Write; + use std::io; use streamer::{allocate, receiver, recycle, sender, Packet, Receiver, Recycler, PACKET_SIZE}; fn producer(addr: &SocketAddr, recycler: Recycler, exit: Arc>) -> JoinHandle<()> { @@ -342,7 +344,10 @@ mod test { t_receiver.join().expect("join"); t_sender.join().expect("join"); } - + #[test] + pub fn streamer_debug() { + write!(io::sink(), "{:?}", Packet::default()).unwrap(); + } #[test] pub fn streamer_send_test() { let read = UdpSocket::bind("127.0.0.1:0").expect("bind");