Move tests into module
@@ -84,6 +84,17 @@ fn multiaddr_to_socketaddr(addr: &Multiaddr) -> Result<SocketAddr, &Multiaddr>
}
}
+#[cfg(test)]
+mod tests {
+ use super::{Tcp, multiaddr_to_socketaddr};
+ use std;
+ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
+ use tokio_io;
+ use futures::Future;
+ use futures::stream::Stream;
+ use multiaddr::Multiaddr;
+ use transport::Transport;
+
#[test]
fn multiaddr_to_tcp_conversion() {
use std::net::{Ipv6Addr};
@@ -117,26 +128,23 @@ fn communicating_between_dialer_and_listener() {
let mut tcp = Tcp::new().unwrap();
let handle = tcp.event_loop.handle();
let listener = tcp.listen_on(addr).unwrap().for_each(|sock| {
- println!("Listening");
// Define what to do with the socket that just connected to us
// Which in this case is read 3 bytes
let handle_conn = tokio_io::io::read_exact(sock, [0; 3]).map(|(_, buf)| {
- println!("Actually read {:?}", buf);
assert_eq!(buf, [1,2,3])
}).map_err(|err| {
panic!("IO error {:?}", err)
});
- println!("handling");
// Spawn the future as a concurrent task
handle.spawn(handle_conn);
Ok(())
});
- println!("starting loop");
tcp.event_loop.run(listener).unwrap();
});
+ std::thread::sleep(std::time::Duration::from_millis(100));
let addr = Multiaddr::new("/ip4/127.0.0.1/tcp/12345").unwrap();
let mut tcp = Tcp::new().unwrap();
// Obtain a future socket through dialing
@@ -153,5 +161,6 @@ fn communicating_between_dialer_and_listener() {
});
// Execute the future in our event loop
tcp.event_loop.run(action).unwrap();
- std::thread::sleep(std::time::Duration::from_millis(1000));
+ std::thread::sleep(std::time::Duration::from_millis(100));
+ }
}
