mirror of https://github.com/fafhrd91/actix-web
issue-1643 add possibility to start test server on particular port
Signed-off-by: Aleksandrov Vladimir <invis87@gmail.com>
This commit is contained in:
parent
75d86a6beb
commit
c12049f5de
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-http-test"
|
||||
version = "2.0.0-alpha.1"
|
||||
version = "2.0.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix HTTP test server"
|
||||
readme = "README.md"
|
||||
|
|
|
@ -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()
|
||||
|
@ -90,7 +98,7 @@ pub async fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer
|
|||
}
|
||||
};
|
||||
|
||||
Client::build().connector(connector).finish()
|
||||
Client::builder().connector(connector).finish()
|
||||
};
|
||||
actix_connect::start_default_resolver().await.unwrap();
|
||||
|
||||
|
|
Loading…
Reference in New Issue