@@ -7,7 +7,7 @@ use std::fs::File;
77use std:: io:: { ErrorKind , Read , Write } ;
88use std:: path:: { Path , PathBuf } ;
99use std:: process:: { Child , Command , Output , Stdio } ;
10- use std:: sync:: { Once , mpsc} ;
10+ use std:: sync:: { Mutex , MutexGuard , Once , mpsc} ;
1111use std:: thread;
1212use std:: time:: { Duration , Instant } ;
1313use tempfile:: TempDir ;
@@ -17,8 +17,10 @@ use testcontainers::{ContainerAsync, GenericImage, ImageExt};
1717use uuid:: Uuid ;
1818
1919static BUILD_RELEASE_BINARIES : Once = Once :: new ( ) ;
20+ static NATS_TEST_LOCK : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
2021
2122pub ( crate ) struct NatsFixture {
23+ _lock : MutexGuard < ' static , ( ) > ,
2224 _container : ContainerAsync < GenericImage > ,
2325 pub ( crate ) nats_url : String ,
2426 pub ( crate ) ws_url : String ,
@@ -259,6 +261,7 @@ pub(crate) fn wait_for_child_stdout_contains(
259261}
260262
261263pub ( crate ) async fn start_nats ( ) -> NatsFixture {
264+ let lock = NATS_TEST_LOCK . lock ( ) . expect ( "NATS test lock" ) ;
262265 let conf = workspace_root ( )
263266 . join ( "crates/contextdb-engine/tests/nats.conf" )
264267 . to_string_lossy ( )
@@ -281,6 +284,7 @@ pub(crate) async fn start_nats() -> NatsFixture {
281284 . await
282285 . expect ( "NATS websocket port should be mapped" ) ;
283286 NatsFixture {
287+ _lock : lock,
284288 _container : container,
285289 nats_url : format ! ( "nats://127.0.0.1:{nats_port}" ) ,
286290 ws_url : format ! ( "ws://127.0.0.1:{ws_port}" ) ,
0 commit comments