Skip to content

Commit

Permalink
Fix wait for app start
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Rehan Saeed committed Dec 6, 2019
1 parent 83b5115 commit d799fde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Source/Boxed.DotnetNewTest/Boxed.DotnetNewTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup Label="Package">
<VersionPrefix>3.1.0</VersionPrefix>
<VersionPrefix>3.1.1</VersionPrefix>
<Authors>Muhammad Rehan Saeed (RehanSaeed.com)</Authors>
<Product>ASP.NET Core Dotnet New Test Boxed</Product>
<Description>ASP.NET Core test framework for dotnet new project templates.</Description>
Expand Down
30 changes: 16 additions & 14 deletions Source/Boxed.DotnetNewTest/ProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,30 +359,32 @@ private static async Task WaitForStartAsync(string url, TimeSpan timeout)
{
const int intervalMilliseconds = 100;

using (var cancellationTokenSource = new CancellationTokenSource(timeout))
using (var httpClientHandler = new HttpClientHandler()
{
AllowAutoRedirect = false,
ServerCertificateCustomValidationCallback = DefaultValidateCertificate,
})
using (var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(url) })
{
using (var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(url) })
while (true)
{
for (var i = 0; i < (timeout.TotalMilliseconds / intervalMilliseconds); ++i)
if (cancellationTokenSource.Token.IsCancellationRequested)
{
try
{
await httpClient.GetAsync(new Uri("/", UriKind.Relative)).ConfigureAwait(false);
return;
}
catch (HttpRequestException exception)
when (IsApiDownException(exception))
{
await Task.Delay(intervalMilliseconds).ConfigureAwait(false);
}
throw new TimeoutException(
$"Timed out after waiting {timeout} for application to start using dotnet run.");
}

throw new TimeoutException(
$"Timed out after waiting {timeout} for application to start using dotnet run.");
try
{
await httpClient.GetAsync(new Uri("/", UriKind.Relative)).ConfigureAwait(false);
return;
}
catch (HttpRequestException exception)
when (IsApiDownException(exception))
{
await Task.Delay(intervalMilliseconds).ConfigureAwait(false);
}
}
}
}
Expand Down

0 comments on commit d799fde

Please sign in to comment.