@@ -61,7 +61,7 @@ defmodule ElixirScope.Foundation.TestSupervisor do
6161 @ spec start_isolated_services ( test_ref ( ) ) :: { :ok , [ pid ( ) ] } | { :error , term ( ) }
6262 def start_isolated_services ( test_ref ) when is_reference ( test_ref ) do
6363 namespace = { :test , test_ref }
64-
64+
6565 Logger . debug ( "Starting isolated services for test namespace #{ inspect ( namespace ) } " )
6666
6767 # Define the services to start with their configurations
@@ -72,19 +72,28 @@ defmodule ElixirScope.Foundation.TestSupervisor do
7272 ]
7373
7474 # Start each service and collect results
75- results =
75+ results =
7676 Enum . map ( service_specs , fn { module , opts } ->
7777 case DynamicSupervisor . start_child ( __MODULE__ , { module , opts } ) do
7878 { :ok , pid } ->
79- Logger . debug ( "Started #{ module } for test namespace #{ inspect ( namespace ) } : #{ inspect ( pid ) } " )
79+ Logger . debug (
80+ "Started #{ module } for test namespace #{ inspect ( namespace ) } : #{ inspect ( pid ) } "
81+ )
82+
8083 { :ok , pid }
8184
8285 { :error , { :already_started , pid } } ->
83- Logger . warning ( "Service #{ module } already started for namespace #{ inspect ( namespace ) } : #{ inspect ( pid ) } " )
86+ Logger . warning (
87+ "Service #{ module } already started for namespace #{ inspect ( namespace ) } : #{ inspect ( pid ) } "
88+ )
89+
8490 { :ok , pid }
8591
8692 { :error , reason } = error ->
87- Logger . error ( "Failed to start #{ module } for namespace #{ inspect ( namespace ) } : #{ inspect ( reason ) } " )
93+ Logger . error (
94+ "Failed to start #{ module } for namespace #{ inspect ( namespace ) } : #{ inspect ( reason ) } "
95+ )
96+
8897 error
8998 end
9099 end )
@@ -93,14 +102,22 @@ defmodule ElixirScope.Foundation.TestSupervisor do
93102 case Enum . split_with ( results , & match? ( { :ok , _ } , & 1 ) ) do
94103 { successes , [ ] } ->
95104 pids = Enum . map ( successes , fn { :ok , pid } -> pid end )
96- Logger . info ( "Successfully started #{ length ( pids ) } services for test namespace #{ inspect ( namespace ) } " )
105+
106+ Logger . info (
107+ "Successfully started #{ length ( pids ) } services for test namespace #{ inspect ( namespace ) } "
108+ )
109+
97110 { :ok , pids }
98111
99112 { _successes , failures } ->
100113 # If any failed, cleanup what we started and return error
101114 cleanup_namespace ( test_ref )
102115 first_error = List . first ( failures )
103- Logger . error ( "Failed to start isolated services for test namespace #{ inspect ( namespace ) } : #{ inspect ( first_error ) } " )
116+
117+ Logger . error (
118+ "Failed to start isolated services for test namespace #{ inspect ( namespace ) } : #{ inspect ( first_error ) } "
119+ )
120+
104121 first_error
105122 end
106123 end
@@ -126,10 +143,10 @@ defmodule ElixirScope.Foundation.TestSupervisor do
126143 @ spec cleanup_namespace ( test_ref ( ) ) :: :ok
127144 def cleanup_namespace ( test_ref ) when is_reference ( test_ref ) do
128145 namespace = { :test , test_ref }
129-
146+
130147 # Only log cleanup debug for non-empty namespaces
131148 services = ProcessRegistry . get_all_services ( namespace )
132-
149+
133150 if map_size ( services ) > 0 do
134151 # Terminate each service through the DynamicSupervisor
135152 Enum . each ( services , fn { _service_name , pid } ->
@@ -148,7 +165,7 @@ defmodule ElixirScope.Foundation.TestSupervisor do
148165
149166 # Wait a moment for cleanup to complete
150167 Process . sleep ( 50 )
151-
168+
152169 # Use ProcessRegistry cleanup as backup
153170 ProcessRegistry . cleanup_test_namespace ( test_ref )
154171 end
@@ -181,10 +198,10 @@ defmodule ElixirScope.Foundation.TestSupervisor do
181198 def get_test_namespaces_info ( ) do
182199 # Get all children of the DynamicSupervisor
183200 children = DynamicSupervisor . which_children ( __MODULE__ )
184-
201+
185202 # Get registry stats
186203 registry_stats = ProcessRegistry . stats ( )
187-
204+
188205 % {
189206 active_children: length ( children ) ,
190207 test_namespaces: registry_stats . test_namespaces ,
@@ -213,12 +230,12 @@ defmodule ElixirScope.Foundation.TestSupervisor do
213230 @ spec wait_for_services_ready ( reference ( ) , pos_integer ( ) ) :: :ok | { :error , :timeout }
214231 def wait_for_services_ready ( test_ref , timeout \\ 5000 ) when is_reference ( test_ref ) do
215232 namespace = { :test , test_ref }
216-
233+
217234 Logger . debug ( "Waiting for services to be ready in namespace #{ inspect ( namespace ) } " )
218235
219236 # Only check for services we actually start (now including TelemetryService)
220237 services_to_check = [ :config_server , :event_store , :telemetry_service ]
221-
238+
222239 start_time = System . monotonic_time ( :millisecond )
223240 wait_for_services_loop ( namespace , services_to_check , timeout , start_time )
224241 end
@@ -242,7 +259,7 @@ defmodule ElixirScope.Foundation.TestSupervisor do
242259 def namespace_healthy? ( test_ref ) when is_reference ( test_ref ) do
243260 namespace = { :test , test_ref }
244261 expected_services = [ :config_server , :event_store , :telemetry_service ]
245-
262+
246263 Enum . all? ( expected_services , fn service ->
247264 case ServiceRegistry . health_check ( namespace , service ) do
248265 { :ok , _pid } -> true
@@ -253,12 +270,16 @@ defmodule ElixirScope.Foundation.TestSupervisor do
253270
254271 ## Private Functions
255272
256- @ spec wait_for_services_loop ( namespace ( ) , [ atom ( ) ] , pos_integer ( ) , integer ( ) ) :: :ok | { :error , :timeout }
273+ @ spec wait_for_services_loop ( namespace ( ) , [ atom ( ) ] , pos_integer ( ) , integer ( ) ) ::
274+ :ok | { :error , :timeout }
257275 defp wait_for_services_loop ( namespace , services , timeout , start_time ) do
258276 elapsed = System . monotonic_time ( :millisecond ) - start_time
259-
277+
260278 if elapsed >= timeout do
261- Logger . warning ( "Timeout waiting for services in namespace #{ inspect ( namespace ) } after #{ elapsed } ms" )
279+ Logger . warning (
280+ "Timeout waiting for services in namespace #{ inspect ( namespace ) } after #{ elapsed } ms"
281+ )
282+
262283 { :error , :timeout }
263284 else
264285 case check_all_services_ready ( namespace , services ) do
@@ -286,4 +307,4 @@ defmodule ElixirScope.Foundation.TestSupervisor do
286307 end
287308 end )
288309 end
289- end
310+ end
0 commit comments