Skip to content

Commit a913fb5

Browse files
committed
Apply changes requested on PR
Signed-off-by: Mateus Devino <mdevino@ibm.com>
1 parent ee77db2 commit a913fb5

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

tests/common/orchestrator.rs

+13-28
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{
2525

2626
use bytes::Bytes;
2727
use eventsource_stream::{EventStream, Eventsource};
28-
use fms_guardrails_orchestr8::{config::OrchestratorConfig, orchestrator::Orchestrator};
28+
use fms_guardrails_orchestr8::{config::OrchestratorConfig, orchestrator::Orchestrator, server};
2929
use futures::{
3030
Stream, StreamExt,
3131
stream::{
@@ -36,7 +36,7 @@ use mocktail::server::MockServer;
3636
use rand::{Rng, SeedableRng, rngs::SmallRng};
3737
use rustls::crypto::ring;
3838
use serde::{Serialize, de::DeserializeOwned};
39-
use tracing::info;
39+
use tracing::{error, warn};
4040
use url::Url;
4141

4242
// Default orchestrator configuration file for integration tests.
@@ -149,9 +149,7 @@ impl TestOrchestratorServer {
149149
}
150150

151151
/// Starts the orchestrator server.
152-
pub async fn start(
153-
config: OrchestratorConfig,
154-
) -> Result<TestOrchestratorServer, anyhow::Error> {
152+
pub async fn start(config: OrchestratorConfig) -> Result<Self, anyhow::Error> {
155153
let mut rng = SmallRng::from_os_rng();
156154
loop {
157155
let port = rng.random_range(10000..60000);
@@ -160,38 +158,25 @@ impl TestOrchestratorServer {
160158
let http_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
161159
let health_http_addr: SocketAddr =
162160
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), health_port);
163-
match fms_guardrails_orchestr8::server::run(
164-
http_addr,
165-
health_http_addr,
166-
None,
167-
None,
168-
None,
169-
orchestrator,
170-
)
171-
.await
172-
{
161+
match server::run(http_addr, health_http_addr, None, None, None, orchestrator).await {
173162
Ok(_) => {
174163
// Give the server time to become ready.
175164
tokio::time::sleep(Duration::from_millis(10)).await;
176-
177-
return Ok(TestOrchestratorServer {
165+
return Ok(Self {
178166
base_url: Url::parse(&format!("http://0.0.0.0:{port}")).unwrap(),
179167
health_url: Url::parse(&format!("http://0.0.0.0:{health_port}/health"))
180168
.unwrap(),
181169
client: reqwest::Client::builder().build().unwrap(),
182170
});
183171
}
184-
Err(error) => match error {
185-
fms_guardrails_orchestr8::server::Error::IoError(_) => {
186-
info!(
187-
"Failed to bind TestOrchestratorServer to ports {port} (guardrails) and {health_port} (health). Trying again using different ports..."
188-
);
189-
continue;
190-
}
191-
error => {
192-
return Err(error.into());
193-
}
194-
},
172+
Err(server::Error::IoError(error)) => {
173+
warn!(%error, "failed to start server, trying again with different ports...");
174+
continue;
175+
}
176+
Err(error) => {
177+
error!(%error, "failed to start server");
178+
return Err(error.into());
179+
}
195180
};
196181
}
197182
}

0 commit comments

Comments
 (0)