diff --git a/tests/Aspire.Hosting.Java.Tests/AddJavaContainerTests.cs b/tests/Aspire.Hosting.Java.Tests/AddJavaContainerTests.cs index b56ecdfa1d8..0e9ab5a8050 100644 --- a/tests/Aspire.Hosting.Java.Tests/AddJavaContainerTests.cs +++ b/tests/Aspire.Hosting.Java.Tests/AddJavaContainerTests.cs @@ -3,6 +3,7 @@ using Aspire.Hosting.ApplicationModel; using Aspire.Hosting.Dcp; +using Aspire.Hosting.Tests.Dcp; using Aspire.Hosting.Tests.Utils; using Aspire.Hosting.Utils; using Microsoft.Extensions.DependencyInjection; @@ -108,20 +109,18 @@ public async Task AddJavaContainer_ExportsTelemetryToAspire() { using var builder = TestDistributedApplicationBuilder.Create(); builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "http://localhost:4317"; + UseFakeDcpInfo(builder, containerHostName: "host.wslc.internal"); var app = builder.AddJavaContainer("catalog", "mycompany/catalog"); // Built rather than evaluated against TestServiceProvider because resolving a container's OTLP // endpoint needs the DCP options that decide how the container reaches the host, which is also - // why the asserted host is not the configured localhost. + // why the asserted host is the one DCP reports rather than the configured localhost. using var built = builder.Build(); var envVars = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync( app.Resource, serviceProvider: built.Services.GetRequiredService()); - var dcpInfo = await built.Services.GetRequiredService().GetDcpInfoAsync(); - var containerHostName = dcpInfo?.Containers?.ContainerHostName ?? KnownHostNames.DockerDesktopHostBridge; - - Assert.Equal($"http://{containerHostName}:4317", envVars["OTEL_EXPORTER_OTLP_ENDPOINT"]); + Assert.Equal("http://host.wslc.internal:4317", envVars["OTEL_EXPORTER_OTLP_ENDPOINT"]); } [Fact] @@ -129,6 +128,7 @@ public async Task WithJvmArgs_AppliesToAContainerToo() { using var builder = TestDistributedApplicationBuilder.Create(); builder.Configuration["ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL"] = "http://localhost:4317"; + UseFakeDcpInfo(builder, containerHostName: "host.docker.internal"); var app = builder.AddJavaContainer("catalog", "mycompany/catalog") .WithJvmArgs(["-Xmx512m"]) @@ -153,4 +153,21 @@ public void AddJavaContainer_KeepsTheJvmBuiltInCertificateAuthorities() var scope = Assert.Single(app.Resource.Annotations.OfType()); Assert.Equal(CertificateTrustScope.System, scope.Scope); } + + // Resolving a container's OTLP endpoint in run mode asks DCP for the container host name. Running the + // real `dcp info` makes these tests depend on how fast the machine's container runtime answers its + // probes, which can exceed DCP's dependency check timeout on busy CI runners. + private static void UseFakeDcpInfo(IDistributedApplicationBuilder builder, string containerHostName) + { + builder.Services.AddSingleton(new TestDcpDependencyCheckService(new DcpInfo + { + Containers = new DcpContainersInfo + { + Runtime = "docker", + Installed = true, + Running = true, + HostName = containerHostName + } + })); + } } diff --git a/tests/Aspire.Hosting.TestUtilities/Aspire.Hosting.TestUtilities.csproj b/tests/Aspire.Hosting.TestUtilities/Aspire.Hosting.TestUtilities.csproj index 94e45519150..ac6c93ba4c7 100644 --- a/tests/Aspire.Hosting.TestUtilities/Aspire.Hosting.TestUtilities.csproj +++ b/tests/Aspire.Hosting.TestUtilities/Aspire.Hosting.TestUtilities.csproj @@ -47,6 +47,7 @@ +