1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-02 08:12:02 +00:00

Add possibility to set address for test_server (#1645)

This commit is contained in:
Aleksandrov Vladimir 2020-09-15 14:09:16 +03:00 committed by GitHub
parent 7f8073233a
commit a429ee6646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -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

View file

@ -44,12 +44,20 @@ pub use actix_testing::*;
/// }
/// ```
pub async fn test_server<F: ServiceFactory<TcpStream>>(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<F: ServiceFactory<TcpStream>>(
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()