Skip to content
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

Add ability to create temp mapped drive for integration tests #8366

Merged
merged 9 commits into from
Feb 8, 2023

Conversation

JanKrivanek
Copy link
Member

Fixes #7330
(plus one subtask of #8329)

Tests only change (no production code affected)

Context

Drive enumeration integration tests need to simulate attempt to enumerate whole drive.
To prevent security and test runtime considerations - a dummy folder is created and mapped to a free letter to be offered to test as a drive for enumeration.

Changes Made

Added utility for mapping drives and mounted to affected unit tests.

src/UnitTests.Shared/DriveMapping.cs Show resolved Hide resolved
Comment on lines 811 to 813
// let's create the mapped drive only once it's needed by any test, then let's reuse;
_mappedDrive ??= new DummyMappedDrive();
unevaluatedInclude = UpdatePathToMappedDrive(unevaluatedInclude, _mappedDrive.MappedDriveLetter);
Copy link
Member

Choose a reason for hiding this comment

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

nit: just wondering if we can request the specific drive instead, imo this makes it a bit more readable

using DummyMappedDrive mappedDrive = DriveMapping.GetDrive("z");

// test content


Copy link
Member Author

Choose a reason for hiding this comment

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

The drive to request is unknown upfront - it needs to be untaken on the system.
So the _mappedDrive takes care about determining one that is free and using it.
Added DriveMapping is utility class that can be used for that purpose.

tl;dr;: Explicit assigning is intentionally hidden in this wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

in this case, using placeholder in test data might be more readable, and then it is replaced by DriveMapping.
e.g: "%DRIVE%:\**\*.cs"

imo, for test purposes picking up 'z' or other letter at the end of abc should work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the %DRIVE%: suggestion! - updated.

I wouldn't use any fixed drive letter though (ppl tend to map shares to various drive letters). The dynamic drive letter allocation logic isn't complicated - so 'd keep it.

{
path = driveLetter + path.Substring(1);
}
return path;
Copy link
Member

Choose a reason for hiding this comment

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

If path is empty, should we return "" or driveLetter + ":"? I'm curious if this could artificially make the drive enumeration tests pass.

Copy link
Member Author

Choose a reason for hiding this comment

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

Empty paths are valid test case scenarios (e.g. unspecified exclude pattern). So it intentionaly leaves unspecified or unrooted paths unaffected

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

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

Looks great, leaving a couple of comments.

src/UnitTests.Shared/DummyMappedDrive.cs Show resolved Hide resolved
src/UnitTests.Shared/DriveMapping.cs Show resolved Hide resolved
src/UnitTests.Shared/DriveMapping.cs Outdated Show resolved Hide resolved
@ladipro
Copy link
Member

ladipro commented Jan 31, 2023

We should also fix the Unix version of these tests. ProjectGetterResultsInUnixDriveEnumerationWarning accounts for almost a minute of test run-time 😢

image

@JanKrivanek
Copy link
Member Author

Added for unix long run and skipping for now: #8373

@JanKrivanek JanKrivanek added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Feb 7, 2023
@JaynieBai JaynieBai merged commit 51df476 into dotnet:main Feb 8, 2023
@JanKrivanek JanKrivanek mentioned this pull request Aug 15, 2023
10 tasks
JaynieBai added a commit that referenced this pull request Oct 10, 2023
Fixes #7330
(plus one subtask of #8329)

Changes Made
Based on Add ability to create temp mapped drive for integration tests #8366 fixes to enable other Drive enumeration integration tests with a dummy folder in windows
Remove one test data https://github.com/dotnet/msbuild/blob/fecef0fdffe59ba8b0251701a23be48bbd552726/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs#L1010-L1012C45 since there is no warning when inlude is not null and exclude with enumerating wildcards. The related logical code is
msbuild/src/Build/Utilities/EngineFileUtilities.cs

Line 339 in fecef0f

 private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec) 
. There is no condition satisfied.
Associate unix Enumeration Tests long time run with issue Unix drive enumeration imports not expanded? #8373
bulatgrzegorz pushed a commit to bulatgrzegorz/selective-condition-evaluator that referenced this pull request Oct 16, 2023
Fixes dotnet#7330
(plus one subtask of dotnet#8329)

Changes Made
Based on Add ability to create temp mapped drive for integration tests dotnet#8366 fixes to enable other Drive enumeration integration tests with a dummy folder in windows
Remove one test data https://github.com/dotnet/msbuild/blob/fecef0fdffe59ba8b0251701a23be48bbd552726/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs#L1010-L1012C45 since there is no warning when inlude is not null and exclude with enumerating wildcards. The related logical code is
msbuild/src/Build/Utilities/EngineFileUtilities.cs

Line 339 in fecef0f

 private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec) 
. There is no condition satisfied.
Associate unix Enumeration Tests long time run with issue Unix drive enumeration imports not expanded? dotnet#8373
MichalPavlik pushed a commit that referenced this pull request Oct 17, 2023
Fixes #7330
(plus one subtask of #8329)

Changes Made
Based on Add ability to create temp mapped drive for integration tests #8366 fixes to enable other Drive enumeration integration tests with a dummy folder in windows
Remove one test data https://github.com/dotnet/msbuild/blob/fecef0fdffe59ba8b0251701a23be48bbd552726/src/Build.OM.UnitTests/Instance/ProjectItemInstance_Tests.cs#L1010-L1012C45 since there is no warning when inlude is not null and exclude with enumerating wildcards. The related logical code is
msbuild/src/Build/Utilities/EngineFileUtilities.cs

Line 339 in fecef0f

 private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLoggingContext targetLoggingContext, IElementLocation includeLocation, IElementLocation excludeLocation, bool excludeFileSpecIsEmpty, bool disableExcludeDriveEnumerationWarning, string fileSpec) 
. There is no condition satisfied.
Associate unix Enumeration Tests long time run with issue Unix drive enumeration imports not expanded? #8373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow MSBuild tests to access root of drive
5 participants