@@ -25,7 +25,7 @@ use std::{
25
25
26
26
use bytes:: Bytes ;
27
27
use eventsource_stream:: { EventStream , Eventsource } ;
28
- use fms_guardrails_orchestr8:: { config:: OrchestratorConfig , orchestrator:: Orchestrator } ;
28
+ use fms_guardrails_orchestr8:: { config:: OrchestratorConfig , orchestrator:: Orchestrator , server } ;
29
29
use futures:: {
30
30
Stream , StreamExt ,
31
31
stream:: {
@@ -36,7 +36,7 @@ use mocktail::server::MockServer;
36
36
use rand:: { Rng , SeedableRng , rngs:: SmallRng } ;
37
37
use rustls:: crypto:: ring;
38
38
use serde:: { Serialize , de:: DeserializeOwned } ;
39
- use tracing:: info ;
39
+ use tracing:: { error , warn } ;
40
40
use url:: Url ;
41
41
42
42
// Default orchestrator configuration file for integration tests.
@@ -149,9 +149,7 @@ impl TestOrchestratorServer {
149
149
}
150
150
151
151
/// 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 > {
155
153
let mut rng = SmallRng :: from_os_rng ( ) ;
156
154
loop {
157
155
let port = rng. random_range ( 10000 ..60000 ) ;
@@ -160,38 +158,25 @@ impl TestOrchestratorServer {
160
158
let http_addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) , port) ;
161
159
let health_http_addr: SocketAddr =
162
160
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 {
173
162
Ok ( _) => {
174
163
// Give the server time to become ready.
175
164
tokio:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
176
-
177
- return Ok ( TestOrchestratorServer {
165
+ return Ok ( Self {
178
166
base_url : Url :: parse ( & format ! ( "http://0.0.0.0:{port}" ) ) . unwrap ( ) ,
179
167
health_url : Url :: parse ( & format ! ( "http://0.0.0.0:{health_port}/health" ) )
180
168
. unwrap ( ) ,
181
169
client : reqwest:: Client :: builder ( ) . build ( ) . unwrap ( ) ,
182
170
} ) ;
183
171
}
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
+ }
195
180
} ;
196
181
}
197
182
}
0 commit comments