Files
tokio/tokio-tcp/tests/limit.rs
T

44 lines
1.0 KiB
Rust
Raw Normal View History

2019-05-14 10:27:36 -07:00
#![deny(warnings, rust_2018_idioms)]
#![cfg(feature = "broken")]
2016-07-30 17:53:12 -07:00
2019-05-14 10:27:36 -07:00
use futures::stream::Stream;
use futures::Future;
2019-02-21 11:56:15 -08:00
use std::io::{Read, Write};
2016-07-30 17:53:12 -07:00
use std::net::TcpStream;
use std::thread;
2017-02-05 17:06:57 -08:00
use tokio_io::io::read_to_end;
use tokio_tcp::TcpListener;
2016-07-30 17:53:12 -07:00
macro_rules! t {
2019-02-21 11:56:15 -08:00
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
}
};
2016-07-30 17:53:12 -07:00
}
#[test]
fn limit() {
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse())));
2016-07-30 17:53:12 -07:00
let addr = t!(srv.local_addr());
let t = thread::spawn(move || {
let mut s1 = TcpStream::connect(&addr).unwrap();
s1.write_all(b"foo bar baz").unwrap();
});
let clients = srv.incoming().take(1);
2016-07-30 17:53:12 -07:00
let copied = clients.collect().and_then(|clients| {
let mut clients = clients.into_iter();
let a = clients.next().unwrap();
2016-08-17 09:29:05 -07:00
read_to_end(a.take(4), Vec::new())
2016-07-30 17:53:12 -07:00
});
let (_, data) = t!(copied.wait());
2016-07-30 17:53:12 -07:00
t.join().unwrap();
assert_eq!(data, b"foo ");
}