Fix Directory_Delete_MountVolume test: guard Unmount calls with Directory.Exists check#125348
Draft
Fix Directory_Delete_MountVolume test: guard Unmount calls with Directory.Exists check#125348
Conversation
…tory.Exists check Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unmount calls in Directory_Delete_MountVolume tests
Fix Directory_Delete_MountVolume test: guard Unmount calls with Directory.Exists check
Mar 9, 2026
Contributor
|
Tagging subscribers to this area: @agocke |
This was referenced Mar 10, 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.
finallyblocks in Scenarios 1, 2, 3.1, and 3.2 unconditionally calledMountHelper.Unmount(mountedDirName). WhenDirectory.Deleteremoves the mount point directory as part of the delete operation, the subsequentUnmountcall throws (Win32 error 4390/3), gets caught by the scenario'scatch, and setss_pass = false.Changes
Delete_MountVolume.cs— Scenarios 1, 2, 3.1, 3.2finallyblocks: WrapUnmount/DeleteDircalls withDirectory.Exists(mountedDirName), matching the pattern already used in Scenarios 3.3–3.5.Original prompt
Problem
The
Directory_Delete_MountVolume.RunTest()test insrc/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Directory/Delete_MountVolume.csfails because thefinallyblocks in Scenarios 1, 2, 3.1, and 3.2 unconditionally callMountHelper.Unmount(mountedDirName), butDirectory.Deletemay have already removed the mount point directory. WhenUnmounttries to callDeleteVolumeMountPointon a path that no longer exists, it throws (Win32 error 4390 or 3), which gets caught by the scenario'scatchblock and setss_pass = false, failing the test.Scenarios 3.3, 3.4, and 3.5 already correctly guard their cleanup with
if (Directory.Exists(mountedDirName))before attempting to unmount. The fix is to apply the same pattern to the 4finallyblocks that are missing it.Fix
Change the
finallyblocks in Scenarios 1, 2, 3.1, and 3.2 to guard theUnmountandDeleteDircalls withDirectory.Exists(mountedDirName), matching the existing pattern used in Scenarios 3.3–3.5.There are exactly 4
finallyblocks to change. Each one currently looks like:Each should be changed to:
The 4 locations in the file
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Directory/Delete_MountVolume.csare:Do not change anything else. No changes to
s_pass,Eval, method signatures, test structure, or any other lines. Only add theDirectory.Existsguard to these 4finallyblocks.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: explain this test to me and what s_pass asserts
Assistant: ## Explanation of
Delete_MountVolume.RunTest()This is a Windows-specific test that verifies
Directory.Deleteworks correctly when NTFS volume mount points are involved. A volume mount point is a directory that acts as an entry point to another volume (similar to a drive letter, but mapped to a folder).What It Tests
The test runs 7 scenarios, all variations of the same theme — deleting directories that are accessed through or contain mounted volumes:
The Pattern in Each Scenario
MountHelper.Mount.finallyblock.What
s_passAssertss_passis a boolean accumulator for the overall test result. It starts astrueand is set tofalsein two situations:Eval(...)call returnsfalse—Evalchecks a condition (e.g., "directory was deleted") and setss_pass = falseif the condition fails, logging the error.catchblock setss_pass = falseand logs the error.At the very end, in the outermost
finally:This is a single assertion that summarizes all scenarios. If any scenario failed a condition or threw an exception,
s_passwill befalseand the test fails. This pattern was common in older test code — it lets the test run all scenarios even if one fails (rather than stopping at the firstAssertfailure), collecting all errors before reporting.Why It's Disabled
The
[ActiveIssue("https://github.com/dotnet/runtime/issues/14378")]attribute means this...This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.