Skip to content

Refactor Tests using Dispose() Pattern in TastExecution Tests#13584

Merged
AlesProkop merged 5 commits intodotnet:mainfrom
AlesProkop:restructure-task-execution-host-tests
Apr 23, 2026
Merged

Refactor Tests using Dispose() Pattern in TastExecution Tests#13584
AlesProkop merged 5 commits intodotnet:mainfrom
AlesProkop:restructure-task-execution-host-tests

Conversation

@AlesProkop
Copy link
Copy Markdown
Member

@AlesProkop AlesProkop commented Apr 21, 2026

Fixes #210

Context

Some of the tests currently contain Dispose() in the setup which is not necessary and tears down the host before building a new one with limited changed fields.

Changes Made

###TaskExecutionHost_Tests.cs
Restructured tests to not contain dispose() by using local variables or changing the required fields that were demanded by the test and differed from the common setup of the testing suite.

Testing

Ran the changed test.

Comment thread src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
@AlesProkop AlesProkop marked this pull request as ready for review April 22, 2026 09:59
Copilot AI review requested due to automatic review settings April 22, 2026 09:59
Copy link
Copy Markdown
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 updates TaskExecutionHost_Tests to avoid calling Dispose() as part of test setup, aligning the tests with more typical xUnit lifecycle patterns and the intent of issue #210.

Changes:

  • Removed the InitializeHost(bool throwOnExecute) setup variant and instead tweaks the task instance directly for the “execute throws” case.
  • Reworked task resolution failure tests to use locally-scoped TaskExecutionHost instances (using var host) instead of disposing/recreating the shared _host.
  • Added a System.Threading.Tasks using (currently unused).

Comment thread src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

makes sense, please think about the naming of the PR so it clearly describes what it does, when looking at git history this does not sound very descriptive.

simple draft from me would be:
"Refactor Dispose pattern in TaskExecutionHost Tests"
(btw you can edit PR descriptions that any time)

@AlesProkop AlesProkop changed the title got rid of dispose in tests that require different setup Refactor Tests using Dispose() Pattern in TastExecution Tests Apr 22, 2026
@AlesProkop AlesProkop enabled auto-merge (squash) April 22, 2026 13:10
Copy link
Copy Markdown
Contributor

@jankratochvilcz jankratochvilcz left a comment

Choose a reason for hiding this comment

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

Can you help me with the reasoning of still having the duplicate InitializeHost? I may be missing some nuance

Comment thread src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
@AlesProkop
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

Comment thread src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
@AlesProkop AlesProkop merged commit 514107a into dotnet:main Apr 23, 2026
10 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.

Restructure TaskExecutionHost tests so per-test cleanup is saner

5 participants