forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_environment.rs
More file actions
34 lines (28 loc) · 1.1 KB
/
test_environment.rs
File metadata and controls
34 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker::bootstrap::jobs::health_check_api::ApiServerJobStarted;
use torrust_tracker::servers::health_check_api::server;
use torrust_tracker_configuration::Configuration;
/// Start the test environment for the Health Check API.
/// It runs the API server.
pub async fn start(config: Arc<Configuration>) -> (SocketAddr, JoinHandle<()>) {
let bind_addr = config
.health_check_api
.bind_address
.parse::<std::net::SocketAddr>()
.expect("Health Check API bind_address invalid.");
let (tx, rx) = oneshot::channel::<ApiServerJobStarted>();
let join_handle = tokio::spawn(async move {
let handle = server::start(bind_addr, tx, config.clone());
if let Ok(()) = handle.await {
panic!("Health Check API server on http://{bind_addr} stopped");
}
});
let bound_addr = match rx.await {
Ok(msg) => msg.bound_addr,
Err(e) => panic!("the Health Check API server was dropped: {e}"),
};
(bound_addr, join_handle)
}