1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 05:41:50 +01:00

use new actix system api

This commit is contained in:
Nikolay Kim 2018-05-29 10:31:37 -07:00
parent fb582a6bca
commit ecd05662c0
13 changed files with 173 additions and 165 deletions

View File

@ -1,16 +1,15 @@
//! Http client api //! Http client api
//! //!
//! ```rust //! ```rust,ignore
//! # extern crate actix; //! # extern crate actix;
//! # extern crate actix_web; //! # extern crate actix_web;
//! # extern crate futures; //! # extern crate futures;
//! # extern crate tokio;
//! # use futures::Future; //! # use futures::Future;
//! use actix_web::client; //! use actix_web::client;
//! //!
//! fn main() { //! fn main() {
//! let sys = actix::System::new("test"); //! tokio::run({
//!
//! actix::Arbiter::spawn({
//! client::get("http://www.rust-lang.org") // <- Create request builder //! client::get("http://www.rust-lang.org") // <- Create request builder
//! .header("User-Agent", "Actix-web") //! .header("User-Agent", "Actix-web")
//! .finish().unwrap() //! .finish().unwrap()
@ -18,12 +17,9 @@
//! .map_err(|_| ()) //! .map_err(|_| ())
//! .and_then(|response| { // <- server http response //! .and_then(|response| { // <- server http response
//! println!("Response: {:?}", response); //! println!("Response: {:?}", response);
//! # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
//! Ok(()) //! Ok(())
//! }) //! })
//! }); //! });
//!
//! sys.run();
//! } //! }
//! ``` //! ```
mod connector; mod connector;
@ -60,17 +56,15 @@ impl ResponseError for SendRequestError {
/// Create request builder for `GET` requests /// Create request builder for `GET` requests
/// ///
/// ```rust /// ```rust,ignore
/// # extern crate actix; /// # extern crate actix;
/// # extern crate actix_web; /// # extern crate actix_web;
/// # extern crate futures; /// # extern crate futures;
/// # use futures::Future; /// # use futures::{future, Future};
/// use actix_web::client; /// use actix_web::client;
/// ///
/// fn main() { /// fn main() {
/// let sys = actix::System::new("test"); /// tokio::run(
///
/// actix::Arbiter::spawn({
/// client::get("http://www.rust-lang.org") // <- Create request builder /// client::get("http://www.rust-lang.org") // <- Create request builder
/// .header("User-Agent", "Actix-web") /// .header("User-Agent", "Actix-web")
/// .finish().unwrap() /// .finish().unwrap()
@ -78,12 +72,8 @@ impl ResponseError for SendRequestError {
/// .map_err(|_| ()) /// .map_err(|_| ())
/// .and_then(|response| { // <- server http response /// .and_then(|response| { // <- server http response
/// println!("Response: {:?}", response); /// println!("Response: {:?}", response);
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// Ok(()) /// Ok(())
/// }) /// }));
/// });
///
/// sys.run();
/// } /// }
/// ``` /// ```
pub fn get<U: AsRef<str>>(uri: U) -> ClientRequestBuilder { pub fn get<U: AsRef<str>>(uri: U) -> ClientRequestBuilder {

View File

@ -380,7 +380,10 @@ impl Pipeline {
match self.timeout.as_mut().unwrap().poll() { match self.timeout.as_mut().unwrap().poll() {
Ok(Async::Ready(())) => return Err(SendRequestError::Timeout), Ok(Async::Ready(())) => return Err(SendRequestError::Timeout),
Ok(Async::NotReady) => (), Ok(Async::NotReady) => (),
Err(_) => unreachable!(), Err(e) => {
println!("err: {:?}", e);
return Err(SendRequestError::Timeout);
}
} }
} }
Ok(()) Ok(())

View File

@ -24,7 +24,7 @@ use httprequest::HttpRequest;
/// An HTTP Client Request /// An HTTP Client Request
/// ///
/// ```rust /// ```rust,ignore
/// # extern crate actix; /// # extern crate actix;
/// # extern crate actix_web; /// # extern crate actix_web;
/// # extern crate futures; /// # extern crate futures;
@ -32,9 +32,7 @@ use httprequest::HttpRequest;
/// use actix_web::client::ClientRequest; /// use actix_web::client::ClientRequest;
/// ///
/// fn main() { /// fn main() {
/// let sys = actix::System::new("test"); /// tokio::run(
///
/// actix::Arbiter::spawn({
/// ClientRequest::get("http://www.rust-lang.org") // <- Create request builder /// ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
/// .header("User-Agent", "Actix-web") /// .header("User-Agent", "Actix-web")
/// .finish().unwrap() /// .finish().unwrap()
@ -42,12 +40,9 @@ use httprequest::HttpRequest;
/// .map_err(|_| ()) /// .map_err(|_| ())
/// .and_then(|response| { // <- server http response /// .and_then(|response| { // <- server http response
/// println!("Response: {:?}", response); /// println!("Response: {:?}", response);
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// Ok(()) /// Ok(())
/// }) /// })
/// }); /// );
///
/// sys.run();
/// } /// }
/// ``` /// ```
pub struct ClientRequest { pub struct ClientRequest {

View File

@ -90,7 +90,7 @@ where
self.inner.cancel_future(handle) self.inner.cancel_future(handle)
} }
#[inline] #[inline]
fn address(&mut self) -> Addr<A> { fn address(&self) -> Addr<A> {
self.inner.address() self.inner.address()
} }
} }

View File

@ -50,7 +50,7 @@
//! } //! }
//! //!
//! fn main() { //! fn main() {
//! let sys = actix::System::new("basic-example"); //! actix::System::run(|| {
//! server::new( //! server::new(
//! || App::new().middleware( //! || App::new().middleware(
//! SessionStorage::new( // <- create session middleware //! SessionStorage::new( // <- create session middleware
@ -60,7 +60,7 @@
//! .bind("127.0.0.1:59880").unwrap() //! .bind("127.0.0.1:59880").unwrap()
//! .start(); //! .start();
//! # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0)); //! # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
//! let _ = sys.run(); //! });
//! } //! }
//! ``` //! ```
use std::cell::RefCell; use std::cell::RefCell;

View File

@ -805,7 +805,7 @@ mod tests {
.unwrap(); .unwrap();
let req = HttpRequest::default(); let req = HttpRequest::default();
let mut ctx = HttpContext::new(req.clone(), MyActor); let ctx = HttpContext::new(req.clone(), MyActor);
let addr = ctx.address(); let addr = ctx.address();
let mut info = PipelineInfo::new(req); let mut info = PipelineInfo::new(req);
info.context = Some(Box::new(ctx)); info.context = Some(Box::new(ctx));

View File

@ -48,7 +48,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// use actix_web::{server, App, HttpResponse}; /// use actix_web::{server, App, HttpResponse};
/// ///
/// fn main() { /// fn main() {
/// let sys = actix::System::new("guide"); /// actix::System::run(|| {
/// ///
/// server::new( /// server::new(
/// || App::new() /// || App::new()
@ -57,7 +57,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// .start(); /// .start();
/// ///
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0)); /// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// let _ = sys.run(); /// });
/// } /// }
/// ``` /// ```
pub fn new<F, U, H>(factory: F) -> HttpServer<H> pub fn new<F, U, H>(factory: F) -> HttpServer<H>

View File

@ -410,7 +410,8 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// use actix_web::{server, App, HttpResponse}; /// use actix_web::{server, App, HttpResponse};
/// ///
/// fn main() { /// fn main() {
/// let sys = actix::System::new("example"); // <- create Actix system /// // Run actix system, this method actually starts all async processes
/// actix::System::run(|| {
/// ///
/// server::new( /// server::new(
/// || App::new() /// || App::new()
@ -418,8 +419,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0") /// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0")
/// .start(); /// .start();
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0)); /// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
/// /// });
/// let _ = sys.run(); // <- Run actix system, this method actually starts all async processes
/// } /// }
/// ``` /// ```
pub fn start(mut self) -> Addr<Self> { pub fn start(mut self) -> Addr<Self> {
@ -496,9 +496,11 @@ impl<H: IntoHttpHandler> HttpServer<H> {
self.no_signals = false; self.no_signals = false;
let _ = thread::spawn(move || { let _ = thread::spawn(move || {
let sys = System::new("http-server"); System::new("http-server")
.config(|| {
self.start(); self.start();
let _ = sys.run(); })
.run();
}).join(); }).join();
} }
} }
@ -565,7 +567,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
/// This method uses only one thread for handling incoming connections. /// This method uses only one thread for handling incoming connections.
pub fn start_incoming<T, S>(mut self, stream: S, secure: bool) -> Addr<Self> pub fn start_incoming<T, S>(mut self, stream: S, secure: bool) -> Addr<Self>
where where
S: Stream<Item = T, Error = io::Error> + 'static, S: Stream<Item = T, Error = io::Error> + Send + 'static,
T: AsyncRead + AsyncWrite + 'static, T: AsyncRead + AsyncWrite + 'static,
{ {
// set server settings // set server settings
@ -588,6 +590,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
})); }));
self self
}); });
if let Some(signals) = signals { if let Some(signals) = signals {
signals.do_send(signal::Subscribe(addr.clone().recipient())) signals.do_send(signal::Subscribe(addr.clone().recipient()))
} }
@ -686,12 +689,13 @@ where
type Result = (); type Result = ();
fn handle(&mut self, msg: Conn<T>, _: &mut Context<Self>) -> Self::Result { fn handle(&mut self, msg: Conn<T>, _: &mut Context<Self>) -> Self::Result {
Arbiter::spawn(HttpChannel::new( unimplemented!();
/*Arbiter::spawn(HttpChannel::new(
Rc::clone(self.h.as_ref().unwrap()), Rc::clone(self.h.as_ref().unwrap()),
msg.io, msg.io,
msg.peer, msg.peer,
msg.http2, msg.http2,
)); ));*/
} }
} }

View File

@ -1,9 +1,10 @@
use futures::unsync::oneshot; use futures::sync::oneshot;
use futures::Future; use futures::Future;
use net2::TcpStreamExt; use net2::TcpStreamExt;
use slab::Slab; use slab::Slab;
use std::rc::Rc; use std::rc::Rc;
use std::{net, time}; use std::{net, time};
use tokio::executor::current_thread;
use tokio_reactor::Handle; use tokio_reactor::Handle;
use tokio_tcp::TcpStream; use tokio_tcp::TcpStream;
@ -180,7 +181,7 @@ impl StreamHandlerType {
let io = TcpStream::from_std(msg.io, &Handle::default()) let io = TcpStream::from_std(msg.io, &Handle::default())
.expect("failed to associate TCP stream"); .expect("failed to associate TCP stream");
Arbiter::spawn(HttpChannel::new(h, io, msg.peer, msg.http2)); current_thread::spawn(HttpChannel::new(h, io, msg.peer, msg.http2));
} }
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
StreamHandlerType::Tls(ref acceptor) => { StreamHandlerType::Tls(ref acceptor) => {
@ -194,9 +195,9 @@ impl StreamHandlerType {
Arbiter::spawn(TlsAcceptorExt::accept_async(acceptor, io).then( Arbiter::spawn(TlsAcceptorExt::accept_async(acceptor, io).then(
move |res| { move |res| {
match res { match res {
Ok(io) => { Ok(io) => current_thread::spawn(HttpChannel::new(
Arbiter::spawn(HttpChannel::new(h, io, peer, http2)) h, io, peer, http2,
} )),
Err(err) => { Err(err) => {
trace!("Error during handling tls connection: {}", err) trace!("Error during handling tls connection: {}", err)
} }
@ -223,7 +224,9 @@ impl StreamHandlerType {
} else { } else {
false false
}; };
Arbiter::spawn(HttpChannel::new(h, io, peer, http2)); current_thread::spawn(HttpChannel::new(
h, io, peer, http2,
));
} }
Err(err) => { Err(err) => {
trace!("Error during handling tls connection: {}", err) trace!("Error during handling tls connection: {}", err)

View File

@ -5,15 +5,13 @@ use std::str::FromStr;
use std::sync::mpsc; use std::sync::mpsc;
use std::{net, thread}; use std::{net, thread};
use actix::{msgs, Actor, Addr, Arbiter, System, SystemRunner}; use actix::{msgs, Actor, Addr, Arbiter, System};
use cookie::Cookie; use cookie::Cookie;
use futures::Future; use futures::Future;
use http::header::HeaderName; use http::header::HeaderName;
use http::{HeaderMap, HttpTryFrom, Method, Uri, Version}; use http::{HeaderMap, HttpTryFrom, Method, Uri, Version};
use net2::TcpBuilder; use net2::TcpBuilder;
use tokio::runtime::current_thread::Runtime; use tokio::runtime::current_thread::Runtime;
use tokio_reactor::Handle;
use tokio_tcp::TcpListener;
#[cfg(feature = "alpn")] #[cfg(feature = "alpn")]
use openssl::ssl::SslAcceptor; use openssl::ssl::SslAcceptor;
@ -63,10 +61,10 @@ use ws;
pub struct TestServer { pub struct TestServer {
addr: net::SocketAddr, addr: net::SocketAddr,
thread: Option<thread::JoinHandle<()>>, thread: Option<thread::JoinHandle<()>>,
system: SystemRunner,
server_sys: Addr<System>, server_sys: Addr<System>,
ssl: bool, ssl: bool,
conn: Addr<ClientConnector>, conn: Addr<ClientConnector>,
rt: Runtime,
} }
impl TestServer { impl TestServer {
@ -113,25 +111,31 @@ impl TestServer {
let sys = System::new("actix-test-server"); let sys = System::new("actix-test-server");
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
let local_addr = tcp.local_addr().unwrap(); let local_addr = tcp.local_addr().unwrap();
let tcp = TcpListener::from_std(tcp, &Handle::default()).unwrap();
sys.config(move || {
HttpServer::new(factory) HttpServer::new(factory)
.disable_signals() .disable_signals()
.start_incoming(tcp.incoming(), false); .listen(tcp)
.start();
tx.send((Arbiter::system(), local_addr)).unwrap(); tx.send((
let _ = sys.run(); Arbiter::system(),
local_addr,
TestServer::get_conn(),
Arbiter::registry().clone(),
)).unwrap();
}).run();
}); });
let sys = System::new("actix-test"); let (server_sys, addr, conn, reg) = rx.recv().unwrap();
let (server_sys, addr) = rx.recv().unwrap(); Arbiter::set_system_reg(reg);
TestServer { TestServer {
addr, addr,
server_sys, server_sys,
conn,
ssl: false, ssl: false,
conn: TestServer::get_conn(),
thread: Some(join), thread: Some(join),
system: sys, rt: Runtime::new().unwrap(),
} }
} }
@ -197,7 +201,7 @@ impl TestServer {
where where
F: Future<Item = I, Error = E>, F: Future<Item = I, Error = E>,
{ {
self.system.run_until_complete(fut) self.rt.block_on(fut)
} }
/// Connect to websocket server /// Connect to websocket server
@ -205,9 +209,8 @@ impl TestServer {
&mut self, &mut self,
) -> Result<(ws::ClientReader, ws::ClientWriter), ws::ClientError> { ) -> Result<(ws::ClientReader, ws::ClientWriter), ws::ClientError> {
let url = self.url("/"); let url = self.url("/");
self.system.run_until_complete( self.rt
ws::Client::with_connector(url, self.conn.clone()).connect(), .block_on(ws::Client::with_connector(url, self.conn.clone()).connect())
)
} }
/// Create `GET` request /// Create `GET` request
@ -285,19 +288,26 @@ impl<S: 'static> TestServerBuilder<S> {
// run server in separate thread // run server in separate thread
let join = thread::spawn(move || { let join = thread::spawn(move || {
let sys = System::new("actix-test-server");
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
let local_addr = tcp.local_addr().unwrap(); let local_addr = tcp.local_addr().unwrap();
let tcp = TcpListener::from_std(tcp, &Handle::default()).unwrap();
let state = self.state; let state = self.state;
System::new("actix-test-server")
.config(move || {
let srv = HttpServer::new(move || { let srv = HttpServer::new(move || {
let mut app = TestApp::new(state()); let mut app = TestApp::new(state());
config(&mut app); config(&mut app);
vec![app] vec![app]
}).disable_signals(); }).workers(1)
.disable_signals();
tx.send((
Arbiter::system(),
local_addr,
TestServer::get_conn(),
Arbiter::registry().clone(),
)).unwrap();
#[cfg(feature = "alpn")] #[cfg(feature = "alpn")]
{ {
@ -309,8 +319,9 @@ impl<S: 'static> TestServerBuilder<S> {
if let Some(ssl) = ssl { if let Some(ssl) = ssl {
srv.start_incoming( srv.start_incoming(
tcp.incoming().and_then(move |sock| { tcp.incoming().and_then(move |sock| {
ssl.accept_async(sock) ssl.accept_async(sock).map_err(|e| {
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)) io::Error::new(io::ErrorKind::Other, e)
})
}), }),
false, false,
); );
@ -320,22 +331,21 @@ impl<S: 'static> TestServerBuilder<S> {
} }
#[cfg(not(feature = "alpn"))] #[cfg(not(feature = "alpn"))]
{ {
srv.start_incoming(tcp.incoming(), false); srv.listen(tcp).start();
} }
})
tx.send((Arbiter::system(), local_addr)).unwrap(); .run();
let _ = sys.run();
}); });
let system = System::new("actix-test"); let (server_sys, addr, conn, reg) = rx.recv().unwrap();
let (server_sys, addr) = rx.recv().unwrap(); Arbiter::set_system_reg(reg);
TestServer { TestServer {
addr, addr,
server_sys,
ssl, ssl,
system, conn,
conn: TestServer::get_conn(), server_sys,
thread: Some(join), thread: Some(join),
rt: Runtime::new().unwrap(),
} }
} }
} }

View File

@ -75,7 +75,7 @@ where
} }
#[inline] #[inline]
fn address(&mut self) -> Addr<A> { fn address(&self) -> Addr<A> {
self.inner.address() self.inner.address()
} }
} }

View File

@ -1,5 +1,7 @@
extern crate actix; extern crate actix;
extern crate actix_web; extern crate actix_web;
#[cfg(feature = "brotli")]
extern crate brotli2;
extern crate bytes; extern crate bytes;
extern crate flate2; extern crate flate2;
extern crate futures; extern crate futures;
@ -10,8 +12,9 @@ extern crate tokio;
extern crate tokio_reactor; extern crate tokio_reactor;
extern crate tokio_tcp; extern crate tokio_tcp;
#[cfg(feature = "brotli")] use std::io::{Read, Write};
extern crate brotli2; use std::sync::{mpsc, Arc};
use std::{net, thread, time};
#[cfg(feature = "brotli")] #[cfg(feature = "brotli")]
use brotli2::write::{BrotliDecoder, BrotliEncoder}; use brotli2::write::{BrotliDecoder, BrotliEncoder};
@ -23,10 +26,8 @@ use futures::stream::once;
use futures::{Future, Stream}; use futures::{Future, Stream};
use h2::client as h2client; use h2::client as h2client;
use modhttp::Request; use modhttp::Request;
use rand::distributions::Alphanumeric;
use rand::Rng; use rand::Rng;
use std::io::{Read, Write};
use std::sync::{mpsc, Arc};
use std::{net, thread, time};
use tokio::executor::current_thread; use tokio::executor::current_thread;
use tokio::runtime::current_thread::Runtime; use tokio::runtime::current_thread::Runtime;
use tokio_tcp::TcpStream; use tokio_tcp::TcpStream;
@ -62,8 +63,8 @@ fn test_start() {
let _ = test::TestServer::unused_addr(); let _ = test::TestServer::unused_addr();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
thread::spawn(move || { thread::spawn(|| {
let sys = System::new("test"); System::run(move || {
let srv = server::new(|| { let srv = server::new(|| {
vec![App::new().resource("/", |r| { vec![App::new().resource("/", |r| {
r.method(http::Method::GET).f(|_| HttpResponse::Ok()) r.method(http::Method::GET).f(|_| HttpResponse::Ok())
@ -74,16 +75,17 @@ fn test_start() {
let addr = srv.addrs()[0]; let addr = srv.addrs()[0];
let srv_addr = srv.start(); let srv_addr = srv.start();
let _ = tx.send((addr, srv_addr)); let _ = tx.send((addr, srv_addr));
sys.run(); });
}); });
let (addr, srv_addr) = rx.recv().unwrap(); let (addr, srv_addr) = rx.recv().unwrap();
let mut sys = System::new("test-server"); let _sys = System::new("test-server");
let mut rt = Runtime::new().unwrap();
{ {
let req = client::ClientRequest::get(format!("http://{}/", addr).as_str()) let req = client::ClientRequest::get(format!("http://{}/", addr).as_str())
.finish() .finish()
.unwrap(); .unwrap();
let response = sys.run_until_complete(req.send()).unwrap(); let response = rt.block_on(req.send()).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
} }
@ -95,7 +97,7 @@ fn test_start() {
.timeout(time::Duration::from_millis(200)) .timeout(time::Duration::from_millis(200))
.finish() .finish()
.unwrap(); .unwrap();
assert!(sys.run_until_complete(req.send()).is_err()); assert!(rt.block_on(req.send()).is_err());
} }
// resume // resume
@ -105,7 +107,7 @@ fn test_start() {
let req = client::ClientRequest::get(format!("http://{}/", addr).as_str()) let req = client::ClientRequest::get(format!("http://{}/", addr).as_str())
.finish() .finish()
.unwrap(); .unwrap();
let response = sys.run_until_complete(req.send()).unwrap(); let response = rt.block_on(req.send()).unwrap();
assert!(response.status().is_success()); assert!(response.status().is_success());
} }
} }
@ -116,8 +118,8 @@ fn test_shutdown() {
let _ = test::TestServer::unused_addr(); let _ = test::TestServer::unused_addr();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
thread::spawn(move || { thread::spawn(|| {
let sys = System::new("test"); System::run(move || {
let srv = server::new(|| { let srv = server::new(|| {
vec![App::new().resource("/", |r| { vec![App::new().resource("/", |r| {
r.method(http::Method::GET).f(|_| HttpResponse::Ok()) r.method(http::Method::GET).f(|_| HttpResponse::Ok())
@ -128,17 +130,17 @@ fn test_shutdown() {
let addr = srv.addrs()[0]; let addr = srv.addrs()[0];
let srv_addr = srv.shutdown_timeout(1).start(); let srv_addr = srv.shutdown_timeout(1).start();
let _ = tx.send((addr, srv_addr)); let _ = tx.send((addr, srv_addr));
sys.run(); });
}); });
let (addr, srv_addr) = rx.recv().unwrap(); let (addr, srv_addr) = rx.recv().unwrap();
let mut sys = System::new("test-server"); let _sys = System::new("test-server");
let mut rt = Runtime::new().unwrap();
{ {
let req = client::ClientRequest::get(format!("http://{}/", addr).as_str()) let req = client::ClientRequest::get(format!("http://{}/", addr).as_str())
.finish() .finish()
.unwrap(); .unwrap();
let response = sys.run_until_complete(req.send()).unwrap(); let response = rt.block_on(req.send()).unwrap();
srv_addr.do_send(server::StopServer { graceful: true }); srv_addr.do_send(server::StopServer { graceful: true });
assert!(response.status().is_success()); assert!(response.status().is_success());
} }
@ -263,7 +265,7 @@ fn test_body_gzip_large() {
#[test] #[test]
fn test_body_gzip_large_random() { fn test_body_gzip_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
.gen_ascii_chars() .sample_iter(&Alphanumeric)
.take(70_000) .take(70_000)
.collect::<String>(); .collect::<String>();
let srv_data = Arc::new(data.clone()); let srv_data = Arc::new(data.clone());
@ -583,7 +585,7 @@ fn test_gzip_encoding_large() {
#[test] #[test]
fn test_reading_gzip_encoding_large_random() { fn test_reading_gzip_encoding_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
.gen_ascii_chars() .sample_iter(&Alphanumeric)
.take(60_000) .take(60_000)
.collect::<String>(); .collect::<String>();
@ -686,7 +688,7 @@ fn test_reading_deflate_encoding_large() {
#[test] #[test]
fn test_reading_deflate_encoding_large_random() { fn test_reading_deflate_encoding_large_random() {
let data = rand::thread_rng() let data = rand::thread_rng()
.gen_ascii_chars() .sample_iter(&Alphanumeric)
.take(160_000) .take(160_000)
.collect::<String>(); .collect::<String>();

View File

@ -7,6 +7,7 @@ extern crate rand;
use bytes::Bytes; use bytes::Bytes;
use futures::Stream; use futures::Stream;
use rand::distributions::Alphanumeric;
use rand::Rng; use rand::Rng;
#[cfg(feature = "alpn")] #[cfg(feature = "alpn")]
@ -86,7 +87,7 @@ fn test_close_description() {
#[test] #[test]
fn test_large_text() { fn test_large_text() {
let data = rand::thread_rng() let data = rand::thread_rng()
.gen_ascii_chars() .sample_iter(&Alphanumeric)
.take(65_536) .take(65_536)
.collect::<String>(); .collect::<String>();
@ -104,7 +105,7 @@ fn test_large_text() {
#[test] #[test]
fn test_large_bin() { fn test_large_bin() {
let data = rand::thread_rng() let data = rand::thread_rng()
.gen_ascii_chars() .sample_iter(&Alphanumeric)
.take(65_536) .take(65_536)
.collect::<String>(); .collect::<String>();