@@ -396,6 +396,15 @@ module AspireTestHost =
396396 part)
397397 |> String.concat " ;"
398398
399+ let private tryGetConnValue ( prefix : string ) ( value : string ) =
400+ value.Split( ';' , StringSplitOptions.RemoveEmptyEntries)
401+ |> Array.tryPick ( fun segment ->
402+ if segment.StartsWith( prefix, StringComparison.OrdinalIgnoreCase) then
403+ Some( segment.Substring( prefix.Length))
404+ else
405+ None)
406+ |> Option.defaultValue " <missing>"
407+
399408 let private formatEnvDiagnostics ( env : Map < string , string >) =
400409 let get key =
401410 match env |> Map.tryFind key with
@@ -468,11 +477,48 @@ module AspireTestHost =
468477 let sw = Stopwatch.StartNew()
469478 let timeout = getTimeout ( TimeSpan.FromSeconds( 60.0 )) ( TimeSpan.FromMinutes( 3.0 ))
470479 let mutable lastError = String.Empty
480+ let mutable attempt = 0
471481 let mutable ready = false
482+ let redactedConnectionString = redactServiceBusConnectionString state.ServiceBusConnectionString
483+ let endpoint = tryGetConnValue " Endpoint=" state.ServiceBusConnectionString
484+
485+ Console.WriteLine(
486+ $" Service Bus readiness probe: Endpoint={endpoint}; Topic={state.ServiceBusTopic}; Subscription={state.ServiceBusTestSubscription}; Connection={redactedConnectionString}"
487+ )
488+
489+ let getResourceDiagnosticsAsync ( resourceName : string ) =
490+ task {
491+ let notificationService =
492+ state.App.Services.GetRequiredService< ResourceNotificationService>()
493+
494+ let details = describeResourceState notificationService resourceName
495+
496+ let! logDetails =
497+ task {
498+ try
499+ let! logLines = getResourceLogsAsync state.App resourceName
500+ return formatLogTail $" {resourceName} logs" logLines 50
501+ with
502+ | ex ->
503+ return $" {resourceName} logs: <failed to capture ({ex.Message})>"
504+ }
505+
506+ return $" {resourceName}: {details}{Environment.NewLine}{logDetails}"
507+ }
472508
473509 while not ready do
474510 if sw.Elapsed >= timeout then
475- raise ( TimeoutException( $" Timed out waiting for Service Bus emulator. Last error: {lastError}" ))
511+ let! emulatorDetails = getResourceDiagnosticsAsync serviceBusEmulatorResourceName
512+ let! sqlDetails = getResourceDiagnosticsAsync serviceBusSqlResourceName
513+ let! dockerDetails = tryGetDockerDiagnosticsAsync ()
514+
515+ raise (
516+ TimeoutException(
517+ $" Timed out waiting for Service Bus emulator. Attempts={attempt}; Elapsed={sw.Elapsed.TotalSeconds:n1}s; Last error: {lastError}{Environment.NewLine}{emulatorDetails}{Environment.NewLine}{sqlDetails}{Environment.NewLine}{dockerDetails}"
518+ )
519+ )
520+
521+ attempt <- attempt + 1
476522
477523 try
478524 let client = ServiceBusClient( state.ServiceBusConnectionString)
@@ -492,6 +538,7 @@ module AspireTestHost =
492538 with
493539 | ex ->
494540 lastError <- ex.Message
541+ Console.WriteLine( $" Service Bus readiness attempt {attempt} failed: {lastError}" )
495542 do ! Task.Delay( TimeSpan.FromSeconds( 1.0 ))
496543 }
497544
0 commit comments