Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Net.Http.Json;
using System.Reflection;
using Aspire.Hosting.Dashboard;
using Aspire.Hosting.Tests;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
Expand Down Expand Up @@ -583,17 +584,20 @@ public async Task DashboardEnabledInTestingBuilderShouldWorkWithDynamicPorts()

await app.StartAsync().DefaultTimeout(TestConstants.LongTimeoutTimeSpan);

// Wait for the dashboard to become healthy, confirming it is actually running.
await app.ResourceNotifications.WaitForResourceHealthyAsync(
"aspire-dashboard",
CancellationToken.None).DefaultTimeout(TestConstants.LongTimeoutTimeSpan);
// Get the allocated dashboard service URI from the app host to confirm the final endpoint.
var dashboardServiceHost = app.Services.GetRequiredService<DashboardServiceHost>();
var resourceServiceUri = await dashboardServiceHost.GetResourceServiceUriAsync().DefaultTimeout(TestConstants.LongTimeoutTimeSpan);

var uri = new Uri(resourceServiceUri);
Assert.Equal("127.0.0.1", uri.Host);
Assert.NotEqual(0, uri.Port);
}

[Theory]
[RequiresFeature(TestFeature.Docker)]
[InlineData("https://127.0.0.1:0")]
[InlineData("https://[::1]:0")]
public async Task LoopbackWithDynamicPorts(string endpointUrl)
[InlineData("https://127.0.0.1:0", "127.0.0.1")]
[InlineData("https://[::1]:0", "[::1]")]
public async Task LoopbackWithDynamicPorts(string endpointUrl, string expectedHost)
{
var builder = DistributedApplicationTestingBuilder.Create([], (opt, _) =>
{
Expand All @@ -608,10 +612,13 @@ public async Task LoopbackWithDynamicPorts(string endpointUrl)
await using var app = await builder.BuildAsync();
await app.StartAsync().DefaultTimeout(TestConstants.LongTimeoutTimeSpan);

// Wait for the dashboard to become healthy, confirming it is actually running.
await app.ResourceNotifications.WaitForResourceHealthyAsync(
"aspire-dashboard",
CancellationToken.None).DefaultTimeout(TestConstants.LongTimeoutTimeSpan);
// Get the allocated dashboard service URI from the app host to confirm the final endpoint.
var dashboardServiceHost = app.Services.GetRequiredService<DashboardServiceHost>();
var resourceServiceUri = await dashboardServiceHost.GetResourceServiceUriAsync().DefaultTimeout(TestConstants.LongTimeoutTimeSpan);

var uri = new Uri(resourceServiceUri);
Assert.Equal(expectedHost, uri.Host);
Assert.NotEqual(0, uri.Port);
}

[Fact]
Expand Down
Loading