@@ -41,6 +41,7 @@ use crate::component_server::{
4141} ;
4242use crate :: serde_utils:: SerdeWrapper ;
4343use crate :: tests:: {
44+ available_ports,
4445 dummy_remote_server_config,
4546 test_a_b_functionality,
4647 ComponentA ,
@@ -55,7 +56,6 @@ use crate::tests::{
5556 ResultB ,
5657 ValueA ,
5758 ValueB ,
58- AVAILABLE_PORTS ,
5959 TEST_LOCAL_CLIENT_METRICS ,
6060 TEST_LOCAL_SERVER_METRICS ,
6161 TEST_REMOTE_CLIENT_METRICS ,
@@ -135,7 +135,7 @@ async fn create_client_and_faulty_server<T>(body: T) -> ComponentAClient
135135where
136136 T : Serialize + DeserializeOwned + Debug + Send + Sync + ' static + Clone ,
137137{
138- let socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
138+ let socket = available_ports ( 0 ) . get_next_local_host_socket ( ) ;
139139 task:: spawn ( async move {
140140 async fn handler < T > (
141141 _http_request : Request < Body > ,
@@ -183,8 +183,9 @@ async fn remote_connection_concurrency() {
183183 const MAX_ATTEMPTS : usize = 50 ;
184184
185185 let setup_value: ValueB = Felt :: from ( 90 ) ;
186- let a_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
187- let b_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
186+ let mut ports = available_ports ( 1 ) ;
187+ let a_socket = ports. get_next_local_host_socket ( ) ;
188+ let b_socket = ports. get_next_local_host_socket ( ) ;
188189
189190 // Shared semaphore used inside ComponentA::handle_request
190191 let semaphore = Arc :: new ( Semaphore :: new ( 0 ) ) ;
@@ -401,8 +402,9 @@ async fn setup_for_tests(
401402#[ tokio:: test]
402403async fn proper_setup ( ) {
403404 let setup_value: ValueB = Felt :: from ( 90 ) ;
404- let a_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
405- let b_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
405+ let mut ports = available_ports ( 2 ) ;
406+ let a_socket = ports. get_next_local_host_socket ( ) ;
407+ let b_socket = ports. get_next_local_host_socket ( ) ;
406408
407409 setup_for_tests ( setup_value, a_socket, b_socket, MAX_CONCURRENCY , None ) . await ;
408410 let a_client_config = RemoteClientConfig :: default ( ) ;
@@ -426,8 +428,9 @@ async fn proper_setup() {
426428
427429#[ tokio:: test]
428430async fn faulty_client_setup ( ) {
429- let a_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
430- let b_socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
431+ let mut ports = available_ports ( 3 ) ;
432+ let a_socket = ports. get_next_local_host_socket ( ) ;
433+ let b_socket = ports. get_next_local_host_socket ( ) ;
431434 // Todo(uriel): Find a better way to pass expected value to the setup
432435 // 123 is some arbitrary value, we don't check it anyway.
433436 setup_for_tests ( Felt :: from ( 123 ) , a_socket, b_socket, MAX_CONCURRENCY , None ) . await ;
@@ -461,7 +464,7 @@ async fn faulty_client_setup() {
461464
462465#[ tokio:: test]
463466async fn unconnected_server ( ) {
464- let socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
467+ let socket = available_ports ( 4 ) . get_next_local_host_socket ( ) ;
465468 let client = ComponentAClient :: new (
466469 FAST_FAILING_CLIENT_CONFIG ,
467470 & socket. ip ( ) . to_string ( ) ,
@@ -494,7 +497,7 @@ async fn faulty_server(
494497
495498#[ tokio:: test]
496499async fn retry_request ( ) {
497- let socket = AVAILABLE_PORTS . lock ( ) . await . get_next_local_host_socket ( ) ;
500+ let socket = available_ports ( 5 ) . get_next_local_host_socket ( ) ;
498501 // Spawn a server that responses with OK every other request.
499502 task:: spawn ( async move {
500503 let should_send_ok = Arc :: new ( Mutex :: new ( false ) ) ;
0 commit comments