Skip to content

Add tests around capturing logs from DistributedApplicationBuilder on failures#15266

Merged
mitchdenny merged 6 commits intomicrosoft:mainfrom
afscrome:executable-log-tests
Mar 27, 2026
Merged

Add tests around capturing logs from DistributedApplicationBuilder on failures#15266
mitchdenny merged 6 commits intomicrosoft:mainfrom
afscrome:executable-log-tests

Conversation

@afscrome
Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15266

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/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
Copy Markdown
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 thread tests/Aspire.Hosting.Tests/ResourceFailureLoggingTests.cs Outdated
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
Copy Markdown
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?

Mitch Denny and others added 2 commits March 27, 2026 16:25
Remove commented-out tests that were blocked by known issues:
- IllegalBindMount (microsoft#13756)
- ContainerExitsImmediatelyAfterStart (microsoft#14262)
- ExecutableDoesNotExist (microsoft#10218)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The exact Docker daemon error message varies across environments. Use
Contains("Error response from daemon") for a more robust assertion,
consistent with the BadImage test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

@mitchdenny mitchdenny merged commit 046a63b into microsoft:main Mar 27, 2026
507 of 510 checks passed
adamint pushed a commit to adamint/aspire that referenced this pull request Mar 28, 2026
… failures (microsoft#15266)

* Add tests around capturing logs from DistributedApplicationBuilder on 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

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Copilot feedback

* Merge main and remove commented-out tests

Remove commented-out tests that were blocked by known issues:
- IllegalBindMount (microsoft#13756)
- ContainerExitsImmediatelyAfterStart (microsoft#14262)
- ExecutableDoesNotExist (microsoft#10218)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix NeedsAuthentication assertion to use Contains instead of EndsWith

The exact Docker daemon error message varies across environments. Use
Contains("Error response from daemon") for a more robust assertion,
consistent with the BadImage test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Mitch Denny <mitch@mitchdeny.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joperezr joperezr added this to the 13.3 milestone Apr 14, 2026
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

5 participants