-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[release/2.1] Fix Granularity for copy operation on unix #31046
Conversation
| [Fact] | ||
| public void CopyToMillisecondPresent() | ||
| { | ||
| FileInfo input = new FileInfo(Path.Combine(TestDirectory, GetTestFileName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can use GetTestFilePath(): it does the Path.Combine of the TestDirectory with GetTestFileName().
| input.Create().Dispose(); | ||
|
|
||
| string driveFormat = new DriveInfo(input.DirectoryName).DriveFormat; | ||
| if (!driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to skip this test on HFS, it'd be better to make this a ConditionalFact that's only executed when the drive format != HFS. (And if for some reason we choose not to do that, the above file creation should be moved to within this if block... there's no benefit to creating the file if we're not going to use it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this be okay
private static bool isHFS = new DriveInfo(Path.GetTempPath()).DriveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase);
| // not support millisecond granularity. | ||
|
|
||
| // If it's 1/1000, or low granularity, this may help: | ||
| Thread.Sleep(1234); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just Thread.Sleep(1)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what the lowest granularity was for all the file systems this might run on. It only happens 1/1000 times, of course.
| // If it's 1/1000, or low granularity, this may help: | ||
| Thread.Sleep(1234); | ||
| input = new FileInfo(Path.Combine(TestDirectory, GetTestFileName())); | ||
| input.Create().Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just call input.Create().Dispose() again on the original input FileInfo?
| input.Create().Dispose(); | ||
| } | ||
|
|
||
| FileInfo output = new FileInfo(Path.Combine(TestDirectory, GetTestFileName(), input.Name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same GetTestFilePath comment.
| output = input.CopyTo(output.FullName, true); | ||
|
|
||
| Assert.NotEqual(0, input.LastWriteTime.Millisecond); | ||
| Assert.NotEqual(0, output.LastWriteTime.Millisecond); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to check that Assert.Equal(input.LastWriteTime, output.LastWriteTime)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't go for that in order for the test fail if for some reason the millisecond granularity is not working. if we go go for equality. the test will still pass if they are zero
| FileInfo output = new FileInfo(Path.Combine(TestDirectory, GetTestFileName(), input.Name)); | ||
|
|
||
| string driveFormat = new DriveInfo(input.DirectoryName).DriveFormat; | ||
| if (driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar ConditionalFact comment. Or if you don't want to use a ConditionalFact, you can just combine the two tests, with one if branch for if it's on HFS, and an else for if it's not.
|
@dotnet-bot test NETFX x86 Release Build |
|
@danmosemsft when can we merge this one ? |
|
We are going to sit on this until we see customer impact. |
|
@danmosemsft can you take a look at the formatting done to the test so that we can merge after that (As it has been approved) |
| { | ||
| public class FileInfo_GetSetTimes : InfoGetSetTimes<FileInfo> | ||
| { | ||
| private static bool isHFS => new DriveInfo(Path.GetTempPath()).DriveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed DriveFormat does not work in AppContainer. I was going to put up a PR to fix that
https://github.com/dotnet/corefx/compare/master...danmosemsft:fix.for.uap?expand=1
I suggest waiting until that's in then pulling that into this PR. The branch isn't open yet anyway
…31164) * Feedback Addressed * Fixing original tests and for appContainers * comment corrected
|
@dotnet-bot test OSX x64 Debug Build |
Fixes https://github.com/dotnet/corefx/issues/12403
This PR ports both of below PRs
#30996
#31164