From 3882e917bb7a706b8696d5cf341eae73c66d1cbb Mon Sep 17 00:00:00 2001 From: Kristian Gaylord Date: Thu, 13 Jul 2023 11:50:38 -0400 Subject: [PATCH] allow configuring number of workers --- actix-test/CHANGES.md | 1 + actix-test/src/lib.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/actix-test/CHANGES.md b/actix-test/CHANGES.md index e3a66c663ad..2a30ee95b2b 100644 --- a/actix-test/CHANGES.md +++ b/actix-test/CHANGES.md @@ -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 diff --git a/actix-test/src/lib.rs b/actix-test/src/lib.rs index 2beb64dca35..d8edb33270b 100644 --- a/actix-test/src/lib.rs +++ b/actix-test/src/lib.rs @@ -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 { @@ -394,6 +397,7 @@ pub struct TestServerConfig { stream: StreamType, client_request_timeout: Duration, port: u16, + workers: usize, } impl Default for TestServerConfig { @@ -410,6 +414,7 @@ impl TestServerConfig { stream: StreamType::Tcp, client_request_timeout: Duration::from_secs(5), port: 0, + workers: 1, } } @@ -452,6 +457,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