Skip to content

Commit

Permalink
Throw on timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Sep 16, 2024
1 parent 03a5bf7 commit 4a58ae7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Lombiq.Tests.UI/Services/FrontendServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,25 @@ public void Configure(
private string GetKey(int orchardPort) =>
StringHelper.CreateInvariant($"{nameof(FrontendServer)}:{Name}:{orchardPort}");

private static Task WaitForStartupAsync(Task mainTask, Task waitTask, TimeSpan? timeout)
private static async Task WaitForStartupAsync(Task mainTask, Task waitTask, TimeSpan? timeout)
{
var tasks = new List<Task>(capacity: 3) { mainTask, waitTask };
if (timeout.HasValue) tasks.Add(Task.Delay(timeout.Value, default(CancellationToken)));

Task? timeoutTask = null;
if (timeout.HasValue)
{
timeoutTask = Task.Delay(timeout.Value, default(CancellationToken));
tasks.Add(timeoutTask);
}

// Use WhenAny in case the CLI task fails before the wait task completes. This prevents hangs.
return Task.WhenAny(tasks).Unwrap();
await Task.WhenAny(tasks).Unwrap();

if (timeoutTask?.IsCompleted == true)
{
throw new TimeoutException(StringHelper.CreateInvariant(
$"The timeout of {nameof(FrontendServer)} ({timeout}) is exceeded."));
}
}

public record Context(
Expand Down

0 comments on commit 4a58ae7

Please sign in to comment.