Skip to content

Xunit 3 upgrade hang fix#1113

Merged
aaronpowell merged 2 commits intoCommunityToolkit:xunit-3-upgradefrom
oising:xunit-3-upgrade
Jan 19, 2026
Merged

Xunit 3 upgrade hang fix#1113
aaronpowell merged 2 commits intoCommunityToolkit:xunit-3-upgradefrom
oising:xunit-3-upgrade

Conversation

@oising
Copy link
Contributor

@oising oising commented Jan 19, 2026

  • Revert @aaronpowell experiment commit
  • add hook for RS pool shutdown tied to host lifecycle application stopping
  • rework initialization pattern to use latest helper extension methods (clarity)

Closes #<ISSUE_NUMBER>

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • New integration
    • Docs are written
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

Copilot AI review requested due to automatic review settings January 19, 2026 18:42
Copy link
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

This PR fixes xUnit 3 test hang issues in the PowerShell integration by adding proper runspace pool shutdown hooks and refactoring the initialization pattern to use modern Aspire helper methods.

Changes:

  • Added IHostApplicationLifetime hook to close PowerShell runspace pools on application shutdown, preventing xUnit 3 from hanging on open foreground threads
  • Refactored initialization pattern to use OnInitializeResource helper method instead of raw event subscriptions for improved clarity
  • Removed flawed script completion tracking logic that had inverted conditional logic

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/CommunityToolkit.Aspire.Hosting.PowerShell/PowerShellRunspacePoolResource.cs Added IHostApplicationLifetime parameter and shutdown hook registration to close runspace pool on application stop; removed flawed script tracking mechanism
src/CommunityToolkit.Aspire.Hosting.PowerShell/PowerShellRunspacePoolResourceBuilderExtensions.cs Refactored script initialization to use OnInitializeResource helper; removed manual script disposal and completion tracking; removed unused System.Drawing import
src/CommunityToolkit.Aspire.Hosting.PowerShell/DistributedApplicationBuilderExtensions.cs Refactored pool initialization pattern using OnInitializeResource helper; reordered code for clarity; added debugger language mode support
tests/CommunityToolkit.Aspire.Hosting.PowerShell.Tests/AppHostTests.cs Removed redundant assertions that are covered by Task.WhenAll behavior
examples/powershell/CommunityToolkit.Aspire.PowerShell.AppHost/Properties/launchSettings.json Added DCP debug logging environment variable
examples/powershell/CommunityToolkit.Aspire.PowerShell.AppHost/Program.cs Added Azurite workaround for known Aspire issue; minor formatting change
Comments suppressed due to low confidence (1)

src/CommunityToolkit.Aspire.Hosting.PowerShell/PowerShellRunspacePoolResource.cs:46

  • The condition logic is inverted. The code checks ScriptsCompleted (which returns true when any script has false value, i.e., NOT completed), but then publishes an update marking the resource as Finished. This appears to be a bug in the removed code that was being fixed.

The removed tracking logic had scriptResourceCompletion.Any(r => r.Value == false) which returns true if any script is NOT completed, but the name ScriptsCompleted suggests it should return true when all scripts ARE completed. This was a logical error that has now been corrected by removing the flawed tracking mechanism.

    internal Task StartAsync(InitialSessionState sessionState, ResourceNotificationService notificationService, ILogger logger, IHostApplicationLifetime hostLifetime, CancellationToken token = default)
    {
        logger.LogInformation(
            "Starting PowerShell runspace pool '{PoolName}' with {MinRunspaces} to {MaxRunspaces} runspaces",
            Name, MinRunspaces, MaxRunspaces);

.WithArgs(2, 3)
.WaitForCompletion(script1);


Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

There's an extra blank line at the end of the file. While this is a minor style issue, it's good practice to maintain consistent formatting without trailing blank lines unless required by the project's style guide.

Suggested change

Copilot uses AI. Check for mistakes.
@aaronpowell aaronpowell merged commit 15e7108 into CommunityToolkit:xunit-3-upgrade Jan 19, 2026
117 of 122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants