mirror of
https://github.com/actix/actix-web.git
synced 2024-11-25 02:51:15 +00:00
actix-test: allow dynamic port setting (#2960)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
fdfb3d45db
commit
fbfff3e751
2 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
## Unreleased - 2022-xx-xx
|
||||
|
||||
- Add `TestServerConfig::port()` setter method.
|
||||
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
|
||||
|
||||
## 0.1.0 - 2022-07-24
|
||||
|
|
|
@ -145,7 +145,7 @@ where
|
|||
// run server in separate orphaned thread
|
||||
thread::spawn(move || {
|
||||
rt::System::new().block_on(async move {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let tcp = net::TcpListener::bind(("127.0.0.1", cfg.port)).unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
let factory = factory.clone();
|
||||
let srv_cfg = cfg.clone();
|
||||
|
@ -390,6 +390,7 @@ pub struct TestServerConfig {
|
|||
tp: HttpVer,
|
||||
stream: StreamType,
|
||||
client_request_timeout: Duration,
|
||||
port: u16,
|
||||
}
|
||||
|
||||
impl Default for TestServerConfig {
|
||||
|
@ -405,6 +406,7 @@ impl TestServerConfig {
|
|||
tp: HttpVer::Both,
|
||||
stream: StreamType::Tcp,
|
||||
client_request_timeout: Duration::from_secs(5),
|
||||
port: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,6 +441,14 @@ impl TestServerConfig {
|
|||
self.client_request_timeout = dur;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets test server port.
|
||||
///
|
||||
/// By default, a random free port is determined by the OS.
|
||||
pub fn port(mut self, port: u16) -> Self {
|
||||
self.port = port;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A basic HTTP server controller that simplifies the process of writing integration tests for
|
||||
|
|
Loading…
Reference in a new issue