-
Notifications
You must be signed in to change notification settings - Fork 739
Enable test logging in DistributedApplicationPipelineTests #13072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ionPipelineTests Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
|
@copilot Keep the original TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish, step: null), but use the extension method WithTestAndResourceLogging as well |
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Updated to keep the original |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13072Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13072" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables comprehensive test logging infrastructure for the DistributedApplicationPipelineTests class, making test failures easier to diagnose by capturing detailed execution logs through xUnit's test output. The changes systematically update all test methods to use proper logging instead of silent null loggers.
Key Changes
- Added
ITestOutputHelperparameter to test class constructor for capturing xUnit output - Updated all 51
TestDistributedApplicationBuilder.Create()calls to chain.WithTestAndResourceLogging(testOutputHelper) - Modified
CreateDeployingContext()to retrieve logger from DI container instead of usingNullLogger.Instance
|
@copilot we also want to add an IPipelineActivityReporter implementation in tests that log to the ITestOutputHelper or ILogger (to capture the steps and logs). |
…r/ILogger Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Added |
| private readonly ITestOutputHelper? _testOutputHelper; | ||
| private readonly ILogger? _logger; | ||
|
|
||
| public TestReportingStep(TestPipelineActivityReporter reporter, string title, ITestOutputHelper? testOutputHelper, ILogger? logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just write to ILogger. And tests configure the logger to write to test output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated TestPipelineActivityReporter to only write to ILogger. Tests now configure the logger to write to test output via WithTestAndResourceLogging(testOutputHelper). Commit: 570ebae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a bug 😄
| private readonly ITestOutputHelper? _testOutputHelper; | ||
| private readonly ILogger? _logger; | ||
|
|
||
| public TestReportingTask(TestPipelineActivityReporter reporter, string initialStatusText, ITestOutputHelper? testOutputHelper, ILogger? logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous. Just write to logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to only use ILogger throughout. All logging now goes through the structured logging API. Commit: 570ebae
|
@copilot implement the feedback |
|
@copilot Make TestPipelineActivityReporter inject builder.Services.AddSingleton<IPipelineActivityReporter, TestPipelineActivityReporter>(); |
…ogger Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Changed constructor to accept |
|
@copilot Add the TestPipelineActivityReporter to all DistributedApplicationPipelineTests |
…eTests Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Added |
|
@copilot the DistributedApplicationPipelineTests seem to be hanging now. Can you figure out which ones are hanging? Make sure we have timeouts on the calls to ExecuteAsync |
…nging tests Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Added |
|
@copilot It's still hanging, run each test in tests/Aspire.Hosting.Tests/Pipelines/DistributedApplicationPipelineTests.cs, individually to figure out where the hang might be. Today the CI is running this: And it is hanging for 60 minutes on this PR still. |
…gger calls Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Found the issue! The Fixed by removing all |
|
@copilot Sicne the logger is no longer used, we should instead directly inject and use the ITestOutputHelper directly in TestPipelineActivityReporter. Add it to the DI container and inject into the TestPipelineActivityReporter ctor |
…of ILogger Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Updated |
|
@copilot We should be writing to the _testOutputHelper in the TestPipelineActivityReporter, in each method |
…output Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Added
The hierarchical indentation makes it easy to see the structure of pipeline execution in test output. Commit: d97f1c3 |
Description
The
DistributedApplicationPipelineTestsclass was not using the test logging infrastructure, making it difficult to diagnose test failures. Tests were usingNullLogger.Instanceinstead of capturing output through xUnit'sITestOutputHelper.This PR enables comprehensive test logging for all 51 pipeline tests by:
ITestOutputHelperto the test class constructorWithTestAndResourceLogging(testOutputHelper)NullLogger.Instancewith a real logger from the DI containerTestPipelineActivityReporterthat writes pipeline activity (steps, tasks, log messages) directly toITestOutputHelperChanges Made
1. Test Class Constructor
Added
ITestOutputHelper testOutputHelperparameter to enable test output capture.2. Builder Initialization (51 tests)
Updated all
TestDistributedApplicationBuilder.Create()calls to chain.WithTestAndResourceLogging(testOutputHelper):3. CreateDeployingContext Method
Replaced
NullLogger.Instancewith a real logger from DI:4. TestPipelineActivityReporter (New)
Created a reusable test implementation of
IPipelineActivityReporterintests/Shared/that:ITestOutputHelperdirectly via constructorCompletePublishAsync:[CompletePublish] message (State: state)CreateStepAsync:[CreateStep] titleCompleteAsync(step):[CompleteStep:title] text (State: state)(indented)CreateTaskAsync:[CreateTask:step] status(indented)Log:[LogLevel:step] message(indented)CompleteAsync(task):[CompleteTask:task] message (State: state)(indented)UpdateAsync:[UpdateTask:task] status(indented)5. Test Registration (51 tests)
All tests now register both the test output helper and the activity reporter:
6. Timeout Protection (50 tests)
Added
.DefaultTimeout()to allpipeline.ExecuteAsync()calls to prevent tests from hanging (5-second timeout locally, 30 seconds on CI):Bug Fixes During Development
During implementation, an infinite recursion bug was discovered and fixed. An initial attempt to use
ILoggerin the reporter caused the reporter's own log calls to be captured by itself recursively. The solution was to have the reporter write directly toITestOutputHelper.WriteLine()instead, avoiding the logging infrastructure entirely and preventing any possibility of recursion.Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.