mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 21:51:06 +01:00
update tests
This commit is contained in:
parent
d81e72cf06
commit
a08b1eba87
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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<tokio_net::tcp::TcpStream>| {
|
||||
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<tokio_net::tcp::TcpStream>| {
|
||||
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<tokio_net::tcp::TcpStream>| {
|
||||
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<tokio_net::tcp::TcpStream>| {
|
||||
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<tokio_net::tcp::TcpStream>| {
|
||||
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<tokio_net::tcp::TcpStream>| {
|
||||
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>(())
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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<TcpStream>, 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()
|
||||
|
@ -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<TcpStream>| {
|
||||
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()
|
||||
|
@ -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" }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user