Skip to content

Commit

Permalink
migrate integration testing to new crate (actix#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede authored Apr 2, 2021
1 parent 50dc13f commit c54a071
Show file tree
Hide file tree
Showing 41 changed files with 791 additions and 646 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
### Removed
* The `client` mod was removed. Clients should now use `awc` directly.
[871ca5e4](https://github.com/actix/actix-web/commit/871ca5e4ae2bdc22d1ea02701c2992fa8d04aed7)
* Integration testing was moved to new `actix-test` crate. Namely these items from the `test`
module: `TestServer`, `TestServerConfig`, `start`, `start_with`, and `unused_addr`. [#2112]

[#2067]: https://github.com/actix/actix-web/pull/2067
[#2093]: https://github.com/actix/actix-web/pull/2093
[#2094]: https://github.com/actix/actix-web/pull/2094
[#2097]: https://github.com/actix/actix-web/pull/2097
[#2112]: https://github.com/actix/actix-web/pull/2112


## 4.0.0-beta.4 - 2021-03-09
Expand Down
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@ members = [
"actix-web-actors",
"actix-web-codegen",
"actix-http-test",
"actix-test",
]

[features]
default = ["compress", "cookies"]

# content-encoding support
compress = ["actix-http/compress", "awc/compress"]
compress = ["actix-http/compress"]

# support for cookies
cookies = ["actix-http/cookies", "awc/cookies"]
cookies = ["actix-http/cookies"]

# secure cookies feature
secure-cookies = ["actix-http/secure-cookies"]

# openssl
openssl = ["tls-openssl", "actix-tls/accept", "actix-tls/openssl", "awc/openssl"]
openssl = ["actix-http/openssl", "actix-tls/accept", "actix-tls/openssl"]

# rustls
rustls = ["tls-rustls", "actix-tls/accept", "actix-tls/rustls", "awc/rustls"]
rustls = ["actix-http/rustls", "actix-tls/accept", "actix-tls/rustls"]

[[example]]
name = "basic"
Expand All @@ -72,10 +73,6 @@ required-features = ["compress", "cookies"]
name = "on_connect"
required-features = []

[[example]]
name = "client"
required-features = ["rustls"]

[dependencies]
actix-codec = "0.4.0-beta.1"
actix-macros = "0.2.0"
Expand All @@ -88,7 +85,6 @@ actix-tls = { version = "3.0.0-beta.5", default-features = false, optional = tru

actix-web-codegen = "0.5.0-beta.2"
actix-http = "3.0.0-beta.4"
awc = { version = "3.0.0-beta.3", default-features = false }

ahash = "0.7"
bytes = "1"
Expand All @@ -109,32 +105,36 @@ serde_urlencoded = "0.7"
smallvec = "1.6"
socket2 = "0.4.0"
time = { version = "0.2.23", default-features = false, features = ["std"] }
tls-openssl = { package = "openssl", version = "0.10.9", optional = true }
tls-rustls = { package = "rustls", version = "0.19.0", optional = true }
url = "2.1"

[dev-dependencies]
actix-test = { version = "0.0.1", features = ["openssl", "rustls"] }
awc = { version = "3.0.0-beta.3", features = ["openssl"] }

brotli2 = "0.3.2"
criterion = "0.3"
env_logger = "0.8"
flate2 = "1.0.13"
rand = "0.8"
rcgen = "0.8"
serde_derive = "1.0"
tls-openssl = { package = "openssl", version = "0.10.9" }
tls-rustls = { package = "rustls", version = "0.19.0" }

[profile.release]
lto = true
opt-level = 3
codegen-units = 1

[patch.crates-io]
actix-web = { path = "." }
actix-files = { path = "actix-files" }
actix-http = { path = "actix-http" }
actix-http-test = { path = "actix-http-test" }
actix-multipart = { path = "actix-multipart" }
actix-test = { path = "actix-test" }
actix-web = { path = "." }
actix-web-actors = { path = "actix-web-actors" }
actix-web-codegen = { path = "actix-web-codegen" }
actix-multipart = { path = "actix-multipart" }
actix-files = { path = "actix-files" }
awc = { path = "awc" }

[[bench]]
Expand Down
1 change: 1 addition & 0 deletions actix-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ percent-encoding = "2.1"
[dev-dependencies]
actix-rt = "2.2"
actix-web = "4.0.0-beta.4"
actix-test = "0.0.1"
6 changes: 3 additions & 3 deletions actix-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ mod tests {

#[actix_rt::test]
async fn test_named_file_content_range_headers() {
let srv = test::start(|| App::new().service(Files::new("/", ".")));
let srv = actix_test::start(|| App::new().service(Files::new("/", ".")));

// Valid range header
let response = srv
Expand All @@ -438,7 +438,7 @@ mod tests {

#[actix_rt::test]
async fn test_named_file_content_length_headers() {
let srv = test::start(|| App::new().service(Files::new("/", ".")));
let srv = actix_test::start(|| App::new().service(Files::new("/", ".")));

// Valid range header
let response = srv
Expand Down Expand Up @@ -477,7 +477,7 @@ mod tests {

#[actix_rt::test]
async fn test_head_content_length_headers() {
let srv = test::start(|| App::new().service(Files::new("/", ".")));
let srv = actix_test::start(|| App::new().service(Files::new("/", ".")));

let response = srv.head("/tests/test.binary").send().await.unwrap();

Expand Down
20 changes: 10 additions & 10 deletions actix-http-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ pub async fn test_server_with_addr<F: ServiceFactory<TcpStream>>(
}
}

/// Get first available unused 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 = net::TcpListener::from(socket);
tcp.local_addr().unwrap()
}

/// Test server controller
pub struct TestServer {
addr: net::SocketAddr,
Expand Down Expand Up @@ -279,3 +269,13 @@ impl Drop for TestServer {
self.stop()
}
}

/// Get a localhost socket address with random, unused port.
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 = net::TcpListener::from(socket);
tcp.local_addr().unwrap()
}
2 changes: 1 addition & 1 deletion actix-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ actix-service = "2.0.0-beta.4"
actix-codec = "0.4.0-beta.1"
actix-utils = "3.0.0-beta.4"
actix-rt = "2.2"
actix-tls = "3.0.0-beta.5"
actix-tls = { version = "3.0.0-beta.5", features = ["accept", "connect"] }

ahash = "0.7"
base64 = "0.13"
Expand Down
18 changes: 16 additions & 2 deletions actix-http/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ where
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,

B: MessageBody + 'static,

X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::InitError: fmt::Debug,

U: ServiceFactory<
(Request, Framed<TcpStream, h1::Codec>),
Config = (),
Expand Down Expand Up @@ -187,11 +190,12 @@ where

#[cfg(feature = "openssl")]
mod openssl {
use super::*;
use actix_service::ServiceFactoryExt;
use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream};
use actix_tls::accept::TlsError;

use super::*;

impl<S, B, X, U> HttpService<TlsStream<TcpStream>, S, B, X, U>
where
S: ServiceFactory<Request, Config = ()>,
Expand All @@ -200,11 +204,14 @@ mod openssl {
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,

B: MessageBody + 'static,

X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::InitError: fmt::Debug,

U: ServiceFactory<
(Request, Framed<TlsStream<TcpStream>, h1::Codec>),
Config = (),
Expand Down Expand Up @@ -266,11 +273,14 @@ mod rustls {
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,

B: MessageBody + 'static,

X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::InitError: fmt::Debug,

U: ServiceFactory<
(Request, Framed<TlsStream<TcpStream>, h1::Codec>),
Config = (),
Expand All @@ -280,7 +290,7 @@ mod rustls {
U::Error: fmt::Display + Into<Error>,
U::InitError: fmt::Debug,
{
/// Create openssl based service
/// Create rustls based service
pub fn rustls(
self,
mut config: ServerConfig,
Expand Down Expand Up @@ -321,17 +331,21 @@ impl<T, S, B, X, U> ServiceFactory<(T, Protocol, Option<net::SocketAddr>)>
for HttpService<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin + 'static,

S: ServiceFactory<Request, Config = ()>,
S::Future: 'static,
S::Error: Into<Error> + 'static,
S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static,

B: MessageBody + 'static,

X: ServiceFactory<Request, Config = (), Response = Request>,
X::Future: 'static,
X::Error: Into<Error>,
X::InitError: fmt::Debug,

U: ServiceFactory<(Request, Framed<T, h1::Codec>), Config = (), Response = ()>,
U::Future: 'static,
U::Error: fmt::Display + Into<Error>,
Expand Down
6 changes: 6 additions & 0 deletions actix-test/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changes

## Unreleased - 2021-xx-xx
* Move integration testing structs from `actix-web`. [#???]

[#???]: https://github.com/actix/actix-web/pull/???
35 changes: 35 additions & 0 deletions actix-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "actix-test"
version = "0.0.1"
authors = ["Rob Ede <[email protected]>"]
edition = "2018"
description = "Integration testing tools for Actix Web applications"
license = "MIT OR Apache-2.0"

[features]
default = []

# rustls
rustls = ["tls-rustls", "actix-http/rustls"]

# openssl
openssl = ["tls-openssl", "actix-http/openssl"]

[dependencies]
actix-codec = "0.4.0-beta.1"
actix-http = { version = "3.0.0-beta.4", features = ["cookies"] }
actix-http-test = { version = "3.0.0-beta.3", features = [] }
actix-service = "2.0.0-beta.4"
actix-utils = "3.0.0-beta.2"
actix-web = { version = "4.0.0-beta.4", default-features = false, features = ["cookies"] }
actix-rt = "2.1"
awc = { version = "3.0.0-beta.3", default-features = false, features = ["cookies"] }

futures-core = { version = "0.3.7", default-features = false, features = ["std"] }
futures-util = { version = "0.3.7", default-features = false, features = [] }
log = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_urlencoded = "0.7"
tls-openssl = { package = "openssl", version = "0.10.9", optional = true }
tls-rustls = { package = "rustls", version = "0.19.0", optional = true }
1 change: 1 addition & 0 deletions actix-test/LICENSE-APACHE
1 change: 1 addition & 0 deletions actix-test/LICENSE-MIT
Loading

0 comments on commit c54a071

Please sign in to comment.