Skip to content

[release/9.0-staging][wbt] Prevent InvalidOperationException on TestOutputHelper logging. #116916

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

Open
wants to merge 9 commits into
base: release/9.0-staging
Choose a base branch
from

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Jun 23, 2025

Tell mode, it updates only the tests.

Contributes to #105315.

Fix race condition causing "There is no currently active test" exceptions:

  • Wrap TestOutputHelper.WriteLine calls in try-catch blocks
  • Continue capturing output even when test context expires
  • Add disposal flags to prevent late handler execution

It also fixes the CI after #116747 merge. The PR disabling MT tests did not remove runtime job dependency on the disabled jobs. That caused runtime jobs not to get triggered as the dependency was not satisfied. This PR disables that dependency.

… write

to xUnit TestOutputHelper after test context has expired.
@ilonatommy ilonatommy self-assigned this Jun 23, 2025
@Copilot Copilot AI review requested due to automatic review settings June 23, 2025 11:07
@ilonatommy ilonatommy added arch-wasm WebAssembly architecture test-enhancement Improvements of test source code labels Jun 23, 2025
@ilonatommy ilonatommy requested a review from maraf as a code owner June 23, 2025 11:07
Copy link
Contributor

@Copilot 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

This PR addresses race conditions that cause InvalidOperationException when logging via TestOutputHelper by adding exception handling, disposal guards, and consolidating logging logic.

  • Wraps all TestOutputHelper.WriteLine calls in try-catch blocks with a warning marker on failure
  • Introduces an isDisposed flag to prevent handlers from writing after disposal
  • Attempts to consolidate duplicate handler logic in ToolCommand

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs Wrapped both error/output data handlers’ WriteLine calls in try-catch blocks
src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs Added isDisposed flag and guards around logging; updated exception and log methods
Comments suppressed due to low confidence (3)

src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs:601

  • Add unit tests that simulate TestOutputHelper context expiration to verify both the exception-catching path and the buffered output fallback are exercised.
            void LogData(string label, string? message)

src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs:490

  • [nitpick] The flag isDisposed is used to guard logging after handlers detach. Consider renaming it to something more descriptive (e.g., handlersDisposed or loggingDisabled) to clarify its purpose.
            bool isDisposed = false;

src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs:620

  • Currently outputBuilder.AppendLine runs unconditionally, which may produce lines with null when message is null. Guard this call with if (message != null) to avoid logging an empty or 'null' message.
                    outputBuilder.AppendLine($"{label} {message}");

@ilonatommy ilonatommy added the Servicing-consider Issue for next servicing release review label Jun 23, 2025
@ilonatommy ilonatommy changed the title [wbt] Prevent InvalidOperationException on TestOutputHelper logging. [release/9.0-staging][wbt] Prevent InvalidOperationException on TestOutputHelper logging. Jun 23, 2025
@ilonatommy
Copy link
Member Author

/azp run runtime

Copy link

Azure Pipelines failed to run 1 pipeline(s).

@ilonatommy
Copy link
Member Author

/azp list

Copy link

CI/CD Pipelines for this repository:

Copy link
Contributor

Tagging subscribers to this area: @akoeplinger, @matouskozak, @simonrozsival
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jeffschwMSFT jeffschwMSFT left a comment

Choose a reason for hiding this comment

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

approved. please get a code review. we will treat this as tell mode

@jeffschwMSFT jeffschwMSFT added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Infrastructure-mono Servicing-approved Approved for servicing release test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants