@@ -393,36 +393,53 @@ module AspireTestHost =
393393 let sw = Stopwatch.StartNew()
394394 let mutable attempt = 0
395395 let mutable lastError = String.Empty
396+ let delayAsync () =
397+ task {
398+ try
399+ do ! Task.Delay( TimeSpan.FromSeconds( 1.0 ), ct)
400+ with
401+ | : ? OperationCanceledException when ct .IsCancellationRequested ->
402+ raise (
403+ TimeoutException(
404+ $" Timed out waiting for Grace.Server HTTP readiness. Last error: {lastError}"
405+ )
406+ )
407+ }
396408
397409 Console.WriteLine( $" Waiting for Grace.Server HTTP readiness at {client.BaseAddress}..." )
398410
399- let rec loop () =
400- task {
401- if ct.IsCancellationRequested then
402- raise ( TimeoutException( $" Timed out waiting for Grace.Server HTTP readiness. Last error: {lastError}" ))
411+ let mutable ready = false
403412
404- attempt <- attempt + 1
413+ while not ready do
414+ if ct.IsCancellationRequested then
415+ raise (
416+ TimeoutException( $" Timed out waiting for Grace.Server HTTP readiness. Last error: {lastError}" )
417+ )
405418
406- try
407- use linkedCts = CancellationTokenSource.CreateLinkedTokenSource( ct)
408- linkedCts.CancelAfter( perRequestTimeout)
419+ attempt <- attempt + 1
409420
410- use! response = client.GetAsync( " /healthz" , linkedCts.Token)
421+ try
422+ use linkedCts = CancellationTokenSource.CreateLinkedTokenSource( ct)
423+ linkedCts.CancelAfter( perRequestTimeout)
411424
412- if response.IsSuccessStatusCode then
413- Console.WriteLine( $" Grace.Server HTTP readiness confirmed after {sw.Elapsed.TotalSeconds:n1}s (attempt {attempt})." )
414- else
415- lastError <- $" Status {(int response.StatusCode)} {response.StatusCode}"
416- do ! Task.Delay( TimeSpan.FromSeconds( 1.0 ), ct)
417- return ! loop ()
418- with
419- | ex ->
420- lastError <- ex.Message
421- do ! Task.Delay( TimeSpan.FromSeconds( 1.0 ), ct)
422- return ! loop ()
423- }
425+ use! response = client.GetAsync( " /healthz" , linkedCts.Token)
424426
425- do ! loop ()
427+ if response.IsSuccessStatusCode then
428+ Console.WriteLine(
429+ $" Grace.Server HTTP readiness confirmed after {sw.Elapsed.TotalSeconds:n1}s (attempt {attempt})."
430+ )
431+ ready <- true
432+ else
433+ lastError <- $" Status {(int response.StatusCode)} {response.StatusCode}"
434+ do ! delayAsync ()
435+ with
436+ | :? OperationCanceledException when ct.IsCancellationRequested ->
437+ raise (
438+ TimeoutException( $" Timed out waiting for Grace.Server HTTP readiness. Last error: {lastError}" )
439+ )
440+ | ex ->
441+ lastError <- ex.Message
442+ do ! delayAsync ()
426443 }
427444
428445 let startAsync () =
0 commit comments