summaryrefslogtreecommitdiffstats
path: root/tests/echo.rs
diff options
context:
space:
mode:
authorSam Rijs <srijs@airpost.net>2018-03-15 03:38:59 +1100
committerCarl Lerche <me@carllerche.com>2018-03-14 09:38:59 -0700
commit923a80e098d4d8355c65d3c80e5789ea0cbded95 (patch)
treed3e19b20d4f040ef7b83398a91370c25c245a3b0 /tests/echo.rs
parent64435f5b35efa761a8c3bf67f599e01b27f9d0a6 (diff)
Move tokio::net module into tokio tcp/udp crates (#224)
Diffstat (limited to 'tests/echo.rs')
-rw-r--r--tests/echo.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/tests/echo.rs b/tests/echo.rs
deleted file mode 100644
index d5bdae81..00000000
--- a/tests/echo.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-extern crate env_logger;
-extern crate futures;
-extern crate tokio;
-extern crate tokio_io;
-
-use std::io::{Read, Write};
-use std::net::TcpStream;
-use std::thread;
-
-use futures::Future;
-use futures::stream::Stream;
-use tokio::net::TcpListener;
-use tokio_io::AsyncRead;
-use tokio_io::io::copy;
-
-macro_rules! t {
- ($e:expr) => (match $e {
- Ok(e) => e,
- Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
- })
-}
-
-#[test]
-fn echo_server() {
- drop(env_logger::init());
-
- let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse())));
- let addr = t!(srv.local_addr());
-
- let msg = "foo bar baz";
- let t = thread::spawn(move || {
- let mut s = TcpStream::connect(&addr).unwrap();
-
- for _i in 0..1024 {
- assert_eq!(t!(s.write(msg.as_bytes())), msg.len());
- let mut buf = [0; 1024];
- assert_eq!(t!(s.read(&mut buf)), msg.len());
- assert_eq!(&buf[..msg.len()], msg.as_bytes());
- }
- });
-
- let clients = srv.incoming();
- let client = clients.into_future().map(|e| e.0.unwrap()).map_err(|e| e.0);
- let halves = client.map(|s| s.split());
- let copied = halves.and_then(|(a, b)| copy(a, b));
-
- let (amt, _, _) = t!(copied.wait());
- t.join().unwrap();
-
- assert_eq!(amt, msg.len() as u64 * 1024);
-}