Add tests around capturing logs from DistributedApplicationBuilder on failures#15266
Add tests around capturing logs from DistributedApplicationBuilder on failures#15266mitchdenny merged 6 commits intomicrosoft:mainfrom
Conversation
… 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
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15266Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15266" |
There was a problem hiding this comment.
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
ExecutableResourceFailureLoggingTeststo assert log forwarding when an executable exits immediately. - Add
ContainerResourceFailureLoggingTeststo assert log forwarding on common Docker startup failures (bad args/image/auth). - Include shared
AsyncTestHelpers.csinAspire.Hosting.Containers.Teststo enableDefaultTimeouthelpers.
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 |
| using Microsoft.AspNetCore.InternalTesting; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Testing; |
| 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; |
| var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken); | ||
| cts.CancelAfter(TimeSpan.FromMinutes(1)); | ||
| return cts; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
075e00d to
da7dc57
Compare
| [Fact] | ||
| [RequiresFeature(TestFeature.Docker)] | ||
| // https://github.com/dotnet/aspire/issues/13756 | ||
| public async Task IllegalBindMount() |
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>
|
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.
|
… 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>
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:
FailedToStartif it starts then immediately exists #13760Fixes #14262
Checklist