fix: flush console output after test completion to prevent truncation (#4545)#4553
Merged
fix: flush console output after test completion to prevent truncation (#4545)#4553
Conversation
…#4545) ## Problem Console output was being truncated when tests completed, particularly when tests ended with Console.Write() without a newline. Users reported that "the end of the output is cut" even after the previous fix in c01a6fc. ## Root Cause While commit c01a6fc fixed parallel output mixing by using per-context buffers, it didn't address output truncation at test completion. When a test ends, any buffered console output (from Console.Write without newline) remains in the test context's line buffer but is never flushed to the sinks. This buffered output is lost and doesn't appear in test results or IDE output. ## Solution Added explicit flushing of console interceptors (stdout and stderr) in the TestCoordinator.ExecuteTestInternalAsync() finally block. This ensures all buffered output is captured before test results are reported. The flush happens: - After test execution completes - In the finally block (always executes, even on exception) - Before result reporting (so output is available in results) - While TestContext.Current still points to the test context - With error handling to prevent flush failures from breaking tests ## Testing - Added OutputTruncationTests with tests ending in Console.Write() - Enhanced ParallelConsoleOutputTests with truncation test case - Existing parallel output isolation tests continue to pass Fixes #4545 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Owner
Author
SummaryAdds console output flushing in the test cleanup path to prevent loss of buffered output from Critical IssuesNone found ✅ SuggestionsNone - the implementation is solid:
The fix addresses the root cause described in the PR: buffered output (from Verdict✅ APPROVE - No critical issues |
This was referenced Jan 25, 2026
This was referenced Feb 10, 2026
This was referenced Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Console output was being truncated when tests completed, particularly when tests ended with
Console.Write()without a newline. Users reported that "the end of the output is cut" even after version 1.12.41 (which included the previous fix in c01a6fc).Example scenario:
Root Cause
While commit c01a6fc fixed parallel output mixing by using per-context buffers, it didn't address output truncation at test completion.
When a test ends, any buffered console output (from
Console.Write()without newline) remains in the test context's line buffer but is never flushed to the sinks. This buffered output is lost and doesn't appear in test results or IDE output.Solution
Added explicit flushing of console interceptors (stdout and stderr) in
TestCoordinator.ExecuteTestInternalAsync()finally block:This ensures all buffered output is captured before test results are reported.
Why this location?
TestContext.Currentstill points to the testTesting
OutputTruncationTests.cs- Tests specifically for output ending without newlineParallelConsoleOutputTests.cs- Added Test4 for truncation scenarioImpact
Console.Write()now capture all output[NotInParallel]testsFixes #4545
🤖 Generated with Claude Code