From a429ee66466c8ddb1f6c922dfc9b0758b22d5815 Mon Sep 17 00:00:00 2001 From: Aleksandrov Vladimir Date: Tue, 15 Sep 2020 14:09:16 +0300 Subject: [PATCH] Add possibility to set address for test_server (#1645) --- test-server/CHANGES.md | 4 +++- test-server/src/lib.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md index e71e9d0b8..0a11e2cae 100644 --- a/test-server/CHANGES.md +++ b/test-server/CHANGES.md @@ -2,11 +2,13 @@ ## Unreleased - 2020-xx-xx +* add ability to set address for `TestServer` [#1645] + +[#1645]: https://github.com/actix/actix-web/pull/1645 ## 2.0.0 - 2020-09-11 * Update actix-codec and actix-utils dependencies. - ## 2.0.0-alpha.1 - 2020-05-23 * Update the `time` dependency to 0.2.7 * Update `actix-connect` dependency to 2.0.0-alpha.2 diff --git a/test-server/src/lib.rs b/test-server/src/lib.rs index 5d5750279..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()