Skip to content

Commit

Permalink
allow configuring number of workers
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian1108 committed Jul 14, 2023
1 parent ce3af77 commit 3882e91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions actix-test/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion actix-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -394,6 +397,7 @@ pub struct TestServerConfig {
stream: StreamType,
client_request_timeout: Duration,
port: u16,
workers: usize,
}

impl Default for TestServerConfig {
Expand All @@ -410,6 +414,7 @@ impl TestServerConfig {
stream: StreamType::Tcp,
client_request_timeout: Duration::from_secs(5),
port: 0,
workers: 1,
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3882e91

Please sign in to comment.