1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

allow configuring number of test server workers (#3069)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Kristian Gaylord 2023-07-19 12:48:43 -04:00 committed by GitHub
parent b061f00421
commit 908fb2606e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## Unreleased - 2023-xx-xx
- Add `TestServerConfig::workers()` setter method
- Minimum supported Rust version (MSRV) is now 1.65 due to transitive `time` dependency.
## 0.1.1 - 2023-02-26

View File

@ -154,7 +154,10 @@ where
let srv_cfg = cfg.clone();
let timeout = cfg.client_request_timeout;
let builder = Server::build().workers(1).disable_signals().system_exit();
let builder = Server::build()
.workers(cfg.workers)
.disable_signals()
.system_exit();
let srv = match srv_cfg.stream {
StreamType::Tcp => match srv_cfg.tp {
@ -367,6 +370,7 @@ pub struct TestServerConfig {
stream: StreamType,
client_request_timeout: Duration,
port: u16,
workers: usize,
}
impl Default for TestServerConfig {
@ -383,6 +387,7 @@ impl TestServerConfig {
stream: StreamType::Tcp,
client_request_timeout: Duration::from_secs(5),
port: 0,
workers: 1,
}
}
@ -425,6 +430,14 @@ impl TestServerConfig {
self.port = port;
self
}
/// Sets number of workers in the test server process.
///
/// By default, the server boots with 1 worker
pub fn workers(mut self, workers: usize) -> Self {
self.workers = workers;
self
}
}
/// A basic HTTP server controller that simplifies the process of writing integration tests for