diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md index 079cad74a..01c723f89 100644 --- a/test-server/CHANGES.md +++ b/test-server/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## Unreleased - 2020-xx-xx + +* add ability to set address for `TestServer` [#1645] + +[#1645]: https://github.com/actix/actix-web/pull/1645 + ## [2.0.0-alpha.1] - 2020-05-23 * Update the `time` dependency to 0.2.7 diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index f3df6d1f6..9aa817bc9 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http-test" -version = "2.0.0-alpha.1" +version = "2.0.0" authors = ["Nikolay Kim "] description = "Actix HTTP test server" readme = "README.md" diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs index f6c1183b4..4159c8d86 100644 --- a/test-server/src/lib.rs +++ b/test-server/src/lib.rs @@ -44,12 +44,20 @@ pub use actix_testing::*; /// } /// ``` pub async fn test_server>(factory: F) -> TestServer { + let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); + test_server_with_addr(tcp, factory).await +} + +/// Start [`test server`](./fn.test_server.html) on a concrete Address +pub async fn test_server_with_addr>( + tcp: net::TcpListener, + factory: F, +) -> TestServer { let (tx, rx) = mpsc::channel(); // run server in separate thread thread::spawn(move || { let sys = System::new("actix-test-server"); - let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let local_addr = tcp.local_addr().unwrap(); Server::build() @@ -90,7 +98,7 @@ pub async fn test_server>(factory: F) -> TestServer } }; - Client::build().connector(connector).finish() + Client::builder().connector(connector).finish() }; actix_connect::start_default_resolver().await.unwrap();