From b5eefb4d42bbe96e6ba07a1a8b12026fd7a4041c Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Wed, 30 Dec 2020 05:20:24 +0800 Subject: [PATCH] merge actix-testing into actix-server (#242) --- Cargo.toml | 2 - actix-server/CHANGES.md | 2 +- actix-server/Cargo.toml | 1 - actix-server/src/lib.rs | 2 + .../lib.rs => actix-server/src/test_server.rs | 23 +++--------- actix-service/src/map_config.rs | 2 +- actix-testing/CHANGES.md | 37 ------------------- actix-testing/Cargo.toml | 26 ------------- actix-testing/LICENSE-APACHE | 1 - actix-testing/LICENSE-MIT | 1 - actix-testing/README.md | 9 ----- actix-tls/Cargo.toml | 1 - actix-tls/tests/test_connect.rs | 2 +- 13 files changed, 11 insertions(+), 98 deletions(-) rename actix-testing/src/lib.rs => actix-server/src/test_server.rs (81%) delete mode 100644 actix-testing/CHANGES.md delete mode 100644 actix-testing/Cargo.toml delete mode 120000 actix-testing/LICENSE-APACHE delete mode 120000 actix-testing/LICENSE-MIT delete mode 100644 actix-testing/README.md diff --git a/Cargo.toml b/Cargo.toml index 342f866a..17d1c857 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,6 @@ members = [ "actix-macros", "actix-service", "actix-server", - "actix-testing", "actix-threadpool", "actix-tls", "actix-tracing", @@ -20,7 +19,6 @@ actix-rt = { path = "actix-rt" } actix-macros = { path = "actix-macros" } actix-server = { path = "actix-server" } actix-service = { path = "actix-service" } -actix-testing = { path = "actix-testing" } actix-threadpool = { path = "actix-threadpool" } actix-tls = { path = "actix-tls" } actix-tracing = { path = "actix-tracing" } diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 302ea576..f3b7c93c 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx - +* Merge `actix-testing` to `actix-server` as `test_server` mod. ## 2.0.0-beta.1 - 2020-12-28 * Added explicit info log message on accept queue pause. [#215] diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index c57b8ac6..0bdd5d23 100644 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -36,7 +36,6 @@ slab = "0.4" tokio = { version = "1", features = ["sync"] } [dev-dependencies] -actix-testing = "2.0.0-beta.1" bytes = "1" env_logger = "0.8" futures-util = { version = "0.3.7", default-features = false, features = ["sink"] } diff --git a/actix-server/src/lib.rs b/actix-server/src/lib.rs index 64aca7e4..24129b5a 100644 --- a/actix-server/src/lib.rs +++ b/actix-server/src/lib.rs @@ -11,6 +11,7 @@ mod server; mod service; mod signals; mod socket; +mod test_server; mod waker_queue; mod worker; @@ -18,6 +19,7 @@ pub use self::builder::ServerBuilder; pub use self::config::{ServiceConfig, ServiceRuntime}; pub use self::server::Server; pub use self::service::ServiceFactory; +pub use self::test_server::TestServer; #[doc(hidden)] pub use self::socket::FromStream; diff --git a/actix-testing/src/lib.rs b/actix-server/src/test_server.rs similarity index 81% rename from actix-testing/src/lib.rs rename to actix-server/src/test_server.rs index 57e2c223..627cc675 100644 --- a/actix-testing/src/lib.rs +++ b/actix-server/src/test_server.rs @@ -1,19 +1,9 @@ -//! Various helpers for Actix applications to use during testing. - -#![deny(rust_2018_idioms, nonstandard_style)] -#![allow(clippy::type_complexity, clippy::needless_doctest_main)] -#![doc(html_logo_url = "https://actix.rs/img/logo.png")] -#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] - use std::sync::mpsc; use std::{net, thread}; use actix_rt::{net::TcpStream, System}; -use actix_server::{Server, ServerBuilder, ServiceFactory}; -use socket2::{Domain, Protocol, Socket, Type}; -#[cfg(not(test))] // Work around for rust-lang/rust#62127 -pub use actix_macros::test; +use crate::{Server, ServerBuilder, ServiceFactory}; /// The `TestServer` type. /// @@ -24,7 +14,7 @@ pub use actix_macros::test; /// /// ```rust /// use actix_service::fn_service; -/// use actix_testing::TestServer; +/// use actix_server::TestServer; /// /// #[actix_rt::main] /// async fn main() { @@ -115,11 +105,10 @@ impl TestServer { /// Get first available unused local address pub fn unused_addr() -> net::SocketAddr { let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); - let socket = - Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp())).unwrap(); - socket.bind(&addr.into()).unwrap(); - socket.set_reuse_address(true).unwrap(); - let tcp = socket.into_tcp_listener(); + let socket = mio::net::TcpSocket::new_v4().unwrap(); + socket.bind(addr).unwrap(); + socket.set_reuseaddr(true).unwrap(); + let tcp = socket.listen(1024).unwrap(); tcp.local_addr().unwrap() } } diff --git a/actix-service/src/map_config.rs b/actix-service/src/map_config.rs index d6d6f6b2..1297f7a0 100644 --- a/actix-service/src/map_config.rs +++ b/actix-service/src/map_config.rs @@ -6,7 +6,7 @@ use super::{IntoServiceFactory, ServiceFactory}; /// /// Note that this function consumes the receiving service factory and returns /// a wrapped version of it. -pub fn map_config(factory: I, f: F) -> MapConfig +pub fn map_config(factory: I, f: F) -> MapConfig where I: IntoServiceFactory, SF: ServiceFactory, diff --git a/actix-testing/CHANGES.md b/actix-testing/CHANGES.md deleted file mode 100644 index f23c7521..00000000 --- a/actix-testing/CHANGES.md +++ /dev/null @@ -1,37 +0,0 @@ -# Changes - -## Unreleased - 2021-xx-xx - - -## 2.0.0-beta.1 - 2020-12-28 -* Update `actix-server` to v2.0.0-beta.1. - - -## 1.0.1 - 2020-05-19 -* Replace deprecated `net2` crate with `socket2` -* Remove unused `futures` dependency - - -## 1.0.0 - 2019-12-11 -* Update actix-server to 1.0.0 - - -## 1.0.0-alpha.3 - 2019-12-07 -* Migrate to tokio 0.2 - - -## 1.0.0-alpha.2 - 2019-12-02 -* Re-export `test` attribute macros - - - -## 0.3.0-alpha.1 - 2019-11-22 -* Migrate to std::future - - -## 0.2.0 - 2019-10-14 -* Upgrade actix-server and actix-server-config deps - - -## 0.1.0 - 2019-09-25 -* Initial impl diff --git a/actix-testing/Cargo.toml b/actix-testing/Cargo.toml deleted file mode 100644 index 3f29679e..00000000 --- a/actix-testing/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "actix-testing" -version = "2.0.0-beta.1" -authors = ["Nikolay Kim "] -description = "Various helpers for Actix applications to use during testing" -keywords = ["network", "framework", "async", "futures"] -homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-net.git" -documentation = "https://docs.rs/actix-testing/" -categories = ["network-programming", "asynchronous"] -license = "MIT OR Apache-2.0" -edition = "2018" -readme = "README.md" - -[lib] -name = "actix_testing" -path = "src/lib.rs" - -[dependencies] -actix-rt = "2.0.0-beta.1" -actix-macros = "0.1.0" -actix-server = "2.0.0-beta.1" -actix-service = "2.0.0-beta.1" - -log = "0.4" -socket2 = "0.3" diff --git a/actix-testing/LICENSE-APACHE b/actix-testing/LICENSE-APACHE deleted file mode 120000 index 965b606f..00000000 --- a/actix-testing/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-APACHE \ No newline at end of file diff --git a/actix-testing/LICENSE-MIT b/actix-testing/LICENSE-MIT deleted file mode 120000 index 76219eb7..00000000 --- a/actix-testing/LICENSE-MIT +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-MIT \ No newline at end of file diff --git a/actix-testing/README.md b/actix-testing/README.md deleted file mode 100644 index ae54b46d..00000000 --- a/actix-testing/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Actix test utilities [![crates.io](https://meritbadge.herokuapp.com/actix-testing)](https://crates.io/crates/actix-testint) [![Join the chat at https://gitter.im/actix/actix](https://badges.gitter.im/actix/actix.svg)](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -## Documentation & community resources - -* [User Guide](https://actix.rs/docs/) -* [API Documentation](https://docs.rs/actix-testing/) -* [Chat on gitter](https://gitter.im/actix/actix) -* Cargo package: [actix-http-test](https://crates.io/crates/actix-testing) -* Minimum supported Rust version: 1.46 or later diff --git a/actix-tls/Cargo.toml b/actix-tls/Cargo.toml index 1c24e0eb..2905fd5a 100644 --- a/actix-tls/Cargo.toml +++ b/actix-tls/Cargo.toml @@ -77,7 +77,6 @@ tokio-native-tls = { version = "0.3", optional = true } [dev-dependencies] actix-server = "2.0.0-beta.1" -actix-testing = "2.0.0-beta.1" bytes = "1" env_logger = "0.8" futures-util = { version = "0.3.7", default-features = false, features = ["sink"] } diff --git a/actix-tls/tests/test_connect.rs b/actix-tls/tests/test_connect.rs index fd083893..aa773c7f 100644 --- a/actix-tls/tests/test_connect.rs +++ b/actix-tls/tests/test_connect.rs @@ -2,8 +2,8 @@ use std::io; use actix_codec::{BytesCodec, Framed}; use actix_rt::net::TcpStream; +use actix_server::TestServer; use actix_service::{fn_service, Service, ServiceFactory}; -use actix_testing::TestServer; use bytes::Bytes; use futures_util::sink::SinkExt;