Skip to content

Commit

Permalink
[tests] Wait for services to start
Browse files Browse the repository at this point in the history
The HttpClient used in the tests don't have resilience, so if
`TestProgram` takes longer to startup, then http requests to the
services can fail.

Instead, explicitly wait for `Application started` messages on the
services before sending a request.

Fixes dotnet#5637
  • Loading branch information
radical committed Sep 10, 2024
1 parent 68ec8ea commit 9389b2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 0 additions & 3 deletions tests/Aspire.Hosting.Tests/SlimTestProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public SlimTestProgramTests(SlimTestProgramFixture slimTestProgramFixture)
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/5637", TestPlatforms.Windows)]
public async Task TestProjectStartsAndStopsCleanly()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand All @@ -42,7 +41,6 @@ private static async Task EnsureServicesAreRunning(TestProgram testProgram, Canc
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/5637", TestPlatforms.Windows)]
public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatch()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand All @@ -61,7 +59,6 @@ public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatc
}

[Fact]
[ActiveIssue("https://github.com/dotnet/aspire/issues/5637", TestPlatforms.Windows)]
public async Task TestPortOnEndpointAnnotationAndAllocatedEndpointAnnotationMatchForReplicatedServices()
{
var testProgram = _slimTestProgramFixture.TestProgram;
Expand Down
4 changes: 4 additions & 0 deletions tests/Aspire.Hosting.Tests/TestProgramFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Testing;
using Aspire.Hosting.Tests.Utils;
using Xunit;

namespace Aspire.Hosting.Tests;
Expand Down Expand Up @@ -63,12 +64,15 @@ public override TestProgram CreateTestProgram()
public override async Task WaitReadyStateAsync(CancellationToken cancellationToken = default)
{
// Make sure services A, B and C are running
await App.WaitForTextAsync("Application started.", "servicea", cancellationToken);
using var clientA = App.CreateHttpClient(TestProgram.ServiceABuilder.Resource.Name, "http");
await clientA.GetStringAsync("/", cancellationToken);

await App.WaitForTextAsync("Application started.", "serviceb", cancellationToken);
using var clientB = App.CreateHttpClient(TestProgram.ServiceBBuilder.Resource.Name, "http");
await clientB.GetStringAsync("/", cancellationToken);

await App.WaitForTextAsync("Application started.", "servicec", cancellationToken);
using var clientC = App.CreateHttpClient(TestProgram.ServiceCBuilder.Resource.Name, "http");
await clientC.GetStringAsync("/", cancellationToken);
}
Expand Down

0 comments on commit 9389b2f

Please sign in to comment.