Skip to content

Add tests around capturing logs from DistributedApplicationBuilder on failures#15266

Open
afscrome wants to merge 3 commits intomicrosoft:mainfrom
afscrome:executable-log-tests
Open

Add tests around capturing logs from DistributedApplicationBuilder on failures#15266
afscrome wants to merge 3 commits intomicrosoft:mainfrom
afscrome:executable-log-tests

Conversation

@afscrome
Copy link
Contributor

Description

This PR adds some test cases around making sure that logs get properly written on various resource failure cases. These have had a habit of workign fine one release, then breaking the next so adding these tests should help prevent regressions. (Or at least ensure changes are being made intentionally)

Note, some tests are commented that ought to pass, but don't due to other bugs:

Fixes #14262

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

… failures

Note, some tests are commented that ought to pass, but don't due to various issues.
- microsoft#13760
- microsoft#14262
- microsoft#10218 (comment)
- microsoft#13756
@afscrome afscrome requested a review from mitchdenny as a code owner March 15, 2026 22:21
Copilot AI review requested due to automatic review settings March 15, 2026 22:21
@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15266

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15266"

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new test coverage to validate resource failure logging behavior for executable and container resources, ensuring stdout/stderr and common startup failures are surfaced via resource logging.

Changes:

  • Add ExecutableResourceFailureLoggingTests to assert log forwarding when an executable exits immediately.
  • Add ContainerResourceFailureLoggingTests to assert log forwarding on common Docker startup failures (bad args/image/auth).
  • Include shared AsyncTestHelpers.cs in Aspire.Hosting.Containers.Tests to enable DefaultTimeout helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tests/Aspire.Hosting.Tests/ResourceFailureLoggingTests.cs New executable-resource logging test and helper methods for collecting forwarded log lines
tests/Aspire.Hosting.Containers.Tests/ResourceFailureLoggingTests.cs New container-resource logging tests for common failure scenarios and log extraction helper
tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj Adds shared AsyncTestHelpers compile include needed by new tests

Comment on lines +5 to +8
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
Comment on lines +49 to +61
var container = builder.AddExecutable("pwsh", "pwsh", "")
.WithArgs("-Command", """
Write-Host "Hello from Stdout"
[Console]::Error.WriteLine("Hello from Stderr")
""");
AddFakeLogging(container);

FakeLogCollector logCollector;
using (var app = builder.Build())
{
logCollector = app.Services.GetFakeLogCollector();
await app.StartAsync(cts.Token).DefaultTimeout(TestConstants.DefaultOrchestratorTestLongTimeout);
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.Finished, cts.Token).DefaultTimeout(TestConstants.DefaultOrchestratorTestLongTimeout);
using Aspire.TestUtilities;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Comment on lines +156 to +158
var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
cts.CancelAfter(TimeSpan.FromMinutes(1));
return cts;
afscrome and others added 2 commits March 15, 2026 22:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
[Fact]
[RequiresFeature(TestFeature.Docker)]
// https://github.com/dotnet/aspire/issues/13756
public async Task IllegalBindMount()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[main] Final logs for containers that exit quickly are missing

3 participants