From a08b1eba870082345b91700d5f5aee54cc277c6a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 2 Dec 2019 11:43:52 +0600 Subject: [PATCH] update tests --- actix-connect/Cargo.toml | 2 - actix-connect/src/connector.rs | 2 +- actix-connect/src/lib.rs | 3 +- actix-connect/src/service.rs | 2 +- actix-connect/tests/test_connect.rs | 26 ++++++------- actix-ioframe/Cargo.toml | 2 - actix-ioframe/tests/test_server.rs | 23 +++++------- actix-server/tests/test_server.rs | 58 ++++++----------------------- actix-testing/Cargo.toml | 2 +- 9 files changed, 37 insertions(+), 83 deletions(-) diff --git a/actix-connect/Cargo.toml b/actix-connect/Cargo.toml index 3b8ee90b..987f65cf 100644 --- a/actix-connect/Cargo.toml +++ b/actix-connect/Cargo.toml @@ -42,7 +42,6 @@ either = "1.5.2" futures = "0.3.1" http = { version = "0.1.17", optional = true } log = "0.4" -tokio-net = "=0.2.0-alpha.6" trust-dns-resolver = { version="0.18.0-alpha.1", default-features = false } # openssl @@ -58,4 +57,3 @@ webpki = { version = "0.21", optional = true } [dev-dependencies] bytes = "0.4" actix-testing = { version="0.3.0-alpha.1" } -actix-server-config = "0.3.0-alpha.1" diff --git a/actix-connect/src/connector.rs b/actix-connect/src/connector.rs index b8c54eeb..fa78b8ac 100644 --- a/actix-connect/src/connector.rs +++ b/actix-connect/src/connector.rs @@ -6,9 +6,9 @@ use std::net::SocketAddr; use std::pin::Pin; use std::task::{Context, Poll}; +use actix_rt::net::TcpStream; use actix_service::{Service, ServiceFactory}; use futures::future::{err, ok, BoxFuture, Either, FutureExt, Ready}; -use tokio_net::tcp::TcpStream; use super::connect::{Address, Connect, Connection}; use super::error::ConnectError; diff --git a/actix-connect/src/lib.rs b/actix-connect/src/lib.rs index a7d276ef..4f51670d 100644 --- a/actix-connect/src/lib.rs +++ b/actix-connect/src/lib.rs @@ -20,9 +20,8 @@ pub mod ssl; #[cfg(feature = "uri")] mod uri; -use actix_rt::Arbiter; +use actix_rt::{net::TcpStream, Arbiter}; use actix_service::{pipeline, pipeline_factory, Service, ServiceFactory}; -use tokio_net::tcp::TcpStream; pub use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; pub use trust_dns_resolver::system_conf::read_system_conf; diff --git a/actix-connect/src/service.rs b/actix-connect/src/service.rs index 65fa6d53..e613d909 100644 --- a/actix-connect/src/service.rs +++ b/actix-connect/src/service.rs @@ -2,10 +2,10 @@ use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; +use actix_rt::net::TcpStream; use actix_service::{Service, ServiceFactory}; use either::Either; use futures::future::{ok, Ready}; -use tokio_net::tcp::TcpStream; use trust_dns_resolver::AsyncResolver; use crate::connect::{Address, Connect, Connection}; diff --git a/actix-connect/tests/test_connect.rs b/actix-connect/tests/test_connect.rs index b1ff8f2a..6e052fdd 100644 --- a/actix-connect/tests/test_connect.rs +++ b/actix-connect/tests/test_connect.rs @@ -1,7 +1,7 @@ use std::io; use actix_codec::{BytesCodec, Framed}; -use actix_server_config::Io; +use actix_rt::net::TcpStream; use actix_service::{service_fn, Service, ServiceFactory}; use actix_testing::TestServer; use bytes::Bytes; @@ -14,9 +14,9 @@ use actix_connect::Connect; #[actix_rt::test] async fn test_string() { let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } @@ -33,9 +33,9 @@ async fn test_string() { #[actix_rt::test] async fn test_rustls_string() { let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } @@ -51,9 +51,9 @@ async fn test_rustls_string() { #[actix_rt::test] async fn test_static_str() { let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } @@ -75,9 +75,9 @@ async fn test_static_str() { #[actix_rt::test] async fn test_new_service() { let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } @@ -100,9 +100,9 @@ async fn test_uri() { use http::HttpTryFrom; let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } @@ -121,9 +121,9 @@ async fn test_rustls_uri() { use http::HttpTryFrom; let srv = TestServer::with(|| { - service_fn(|io: Io| { + service_fn(|io: TcpStream| { async { - let mut framed = Framed::new(io.into_parts().0, BytesCodec); + let mut framed = Framed::new(io, BytesCodec); framed.send(Bytes::from_static(b"test")).await?; Ok::<_, io::Error>(()) } diff --git a/actix-ioframe/Cargo.toml b/actix-ioframe/Cargo.toml index e194823b..c5650849 100644 --- a/actix-ioframe/Cargo.toml +++ b/actix-ioframe/Cargo.toml @@ -31,5 +31,3 @@ log = "0.4" [dev-dependencies] actix-connect = "1.0.0-alpha.1" actix-testing = "0.3.0-alpha.1" -actix-server-config = "0.3.0-alpha.1" -tokio-net = "=0.2.0-alpha.6" diff --git a/actix-ioframe/tests/test_server.rs b/actix-ioframe/tests/test_server.rs index 98c95eb5..e8992314 100644 --- a/actix-ioframe/tests/test_server.rs +++ b/actix-ioframe/tests/test_server.rs @@ -4,11 +4,9 @@ use std::time::Duration; use actix_codec::BytesCodec; use actix_rt::time::delay_for; -use actix_server_config::Io; -use actix_service::{apply_fn_factory, service_fn, Service}; +use actix_service::{service_fn, Service}; use actix_testing::TestServer; use futures::future::ok; -use tokio_net::tcp::TcpStream; use actix_ioframe::{Builder, Connect}; @@ -22,17 +20,14 @@ async fn test_disconnect() -> std::io::Result<()> { let srv = TestServer::with(move || { let disconnect1 = disconnect1.clone(); - apply_fn_factory( - Builder::new() - .factory(service_fn(|conn: Connect<_>| { - ok(conn.codec(BytesCodec).state(State)) - })) - .disconnect(move |_, _| { - disconnect1.store(true, Ordering::Relaxed); - }) - .finish(service_fn(|_t| ok(None))), - |io: Io, srv| srv.call(io.into_parts().0), - ) + Builder::new() + .factory(service_fn(|conn: Connect<_>| { + ok(conn.codec(BytesCodec).state(State)) + })) + .disconnect(move |_, _| { + disconnect1.store(true, Ordering::Relaxed); + }) + .finish(service_fn(|_t| ok(None))) }); let mut client = Builder::new() diff --git a/actix-server/tests/test_server.rs b/actix-server/tests/test_server.rs index 22f4a4ab..32761ef0 100644 --- a/actix-server/tests/test_server.rs +++ b/actix-server/tests/test_server.rs @@ -3,12 +3,12 @@ use std::sync::mpsc; use std::{net, thread, time}; use actix_codec::{BytesCodec, Framed}; -use actix_server::{Io, Server, ServerConfig}; -use actix_service::{factory_fn_cfg, service_fn, service_fn2}; +use actix_rt::net::TcpStream; +use actix_server::Server; +use actix_service::service_fn; use bytes::Bytes; use futures::{future::ok, SinkExt}; use net2::TcpBuilder; -use tokio_net::tcp::TcpStream; fn unused_addr() -> net::SocketAddr { let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); @@ -27,12 +27,7 @@ fn test_bind() { let h = thread::spawn(move || { let sys = actix_rt::System::new("test"); let srv = Server::build() - .bind("test", addr, move || { - factory_fn_cfg(move |cfg: &ServerConfig| { - assert_eq!(cfg.local_addr(), addr); - ok::<_, ()>(service_fn2(|_| ok::<_, ()>(()))) - }) - }) + .bind("test", addr, move || service_fn(|_| ok::<_, ()>(()))) .unwrap() .start(); let _ = tx.send((srv, actix_rt::System::current())); @@ -46,26 +41,6 @@ fn test_bind() { let _ = h.join(); } -#[test] -fn test_bind_no_config() { - let addr = unused_addr(); - let (tx, rx) = mpsc::channel(); - - let h = thread::spawn(move || { - let sys = actix_rt::System::new("test"); - let srv = Server::build() - .bind("test", addr, move || service_fn(|_| ok::<_, ()>(()))) - .unwrap() - .start(); - let _ = tx.send((srv, actix_rt::System::current())); - let _ = sys.run(); - }); - let (_, sys) = rx.recv().unwrap(); - assert!(net::TcpStream::connect(addr).is_ok()); - let _ = sys.stop(); - let _ = h.join(); -} - #[test] fn test_listen() { let addr = unused_addr(); @@ -75,12 +50,7 @@ fn test_listen() { let sys = actix_rt::System::new("test"); let lst = net::TcpListener::bind(addr).unwrap(); let srv = Server::build() - .listen("test", lst, move || { - factory_fn_cfg(move |cfg: &ServerConfig| { - assert_eq!(cfg.local_addr(), addr); - ok::<_, ()>(service_fn2(|_| ok::<_, ()>(()))) - }) - }) + .listen("test", lst, move || service_fn(|_| ok::<_, ()>(()))) .unwrap() .start(); let _ = tx.send((srv, actix_rt::System::current())); @@ -105,18 +75,12 @@ fn test_start() { let srv: Server = Server::build() .backlog(100) .bind("test", addr, move || { - factory_fn_cfg(move |cfg: &ServerConfig| { - assert_eq!(cfg.local_addr(), addr); - - let srv = service_fn2(|io: Io| { - async { - let mut f = Framed::new(io.into_parts().0, BytesCodec); - f.send(Bytes::from_static(b"test")).await.unwrap(); - Ok::<_, ()>(()) - } - }); - - ok::<_, ()>(srv) + service_fn(|io: TcpStream| { + async move { + let mut f = Framed::new(io, BytesCodec); + f.send(Bytes::from_static(b"test")).await.unwrap(); + Ok::<_, ()>(()) + } }) }) .unwrap() diff --git a/actix-testing/Cargo.toml b/actix-testing/Cargo.toml index e199d568..97f0150a 100644 --- a/actix-testing/Cargo.toml +++ b/actix-testing/Cargo.toml @@ -26,4 +26,4 @@ actix-service = "1.0.0-alpha.1" log = "0.4" net2 = "0.2" futures = "0.3.1" -tokio-net = { version = "0.2.0-alpha.6" } +