This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Updates Unix FileSystem tests that check millisecond granularity #30763
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ namespace System.IO.Tests | |
| { | ||
| public abstract class BaseGetSetTimes<T> : FileSystemTest | ||
| { | ||
| private const string HFS = "hfs"; | ||
| public delegate void SetTime(T item, DateTime time); | ||
| public delegate DateTime GetTime(T item); | ||
|
|
||
|
|
@@ -71,40 +72,43 @@ public void CanGetAllTimesAfterCreation() | |
| } | ||
|
|
||
| [Fact] | ||
| [PlatformSpecific(TestPlatforms.Linux)] // Windows tested below, and OSX does not currently support millisec granularity | ||
| public void TimesIncludeMillisecondPart_Linux() | ||
| [PlatformSpecific(TestPlatforms.AnyUnix)] // Windows tested below, and OSX HFS driver format does not support millisec granularity | ||
| public void TimesIncludeMillisecondPart_Unix() | ||
| { | ||
| T item = GetExistingItem(); | ||
|
|
||
| string driveFormat = new DriveInfo(GetItemPath(item)).DriveFormat; | ||
|
|
||
| Assert.All(TimeFunctions(), (function) => | ||
| if (!PlatformDetection.IsOSX || | ||
| !driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| var msec = 0; | ||
| for (int i = 0; i < 5; i++) | ||
| Assert.All(TimeFunctions(), (function) => | ||
| { | ||
| DateTime time = function.Getter(item); | ||
| msec = time.Millisecond; | ||
| var msec = 0; | ||
| for (int i = 0; i < 5; i++) | ||
| { | ||
| DateTime time = function.Getter(item); | ||
| msec = time.Millisecond; | ||
|
|
||
| if (msec != 0) | ||
| break; | ||
| if (msec != 0) | ||
| break; | ||
|
|
||
| // This case should only happen 1/1000 times, unless the OS/Filesystem does | ||
| // not support millisecond granularity. | ||
| // This case should only happen 1/1000 times, unless the OS/Filesystem does | ||
| // not support millisecond granularity. | ||
|
|
||
| // If it's 1/1000, or low granularity, this may help: | ||
| Thread.Sleep(1234); | ||
| // If it's 1/1000, or low granularity, this may help: | ||
| Thread.Sleep(1234); | ||
|
|
||
| // If it's the OS/Filesystem often returns 0 for the millisecond part, this may | ||
| // help prove it. This should only be written 1/1000 runs, unless the test is going to | ||
| // fail. | ||
| Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}"); | ||
| // If it's the OS/Filesystem often returns 0 for the millisecond part, this may | ||
| // help prove it. This should only be written 1/1000 runs, unless the test is going to | ||
| // fail. | ||
| Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}"); | ||
|
|
||
| item = GetExistingItem(); // try a new file/directory | ||
| } | ||
| item = GetExistingItem(); // try a new file/directory | ||
| } | ||
|
|
||
| Assert.NotEqual(0, msec); | ||
| }); | ||
| Assert.NotEqual(0, msec); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -137,17 +141,20 @@ public void TimesIncludeMillisecondPart_Windows() | |
| } | ||
|
|
||
| [Fact] | ||
| // OSX does not currently support millisec granularity: use this test as a canary to flag | ||
| // if this ever changes so we can enable the actual test | ||
| [PlatformSpecific(TestPlatforms.OSX)] | ||
| public void TimesIncludeMillisecondPart_OSX() | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment above is now outdated |
||
| T item = GetExistingItem(); | ||
| Assert.All(TimeFunctions(), (function) => | ||
| string driveFormat = new DriveInfo(Path.GetTempPath()).DriveFormat; | ||
| if (driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| DateTime time = function.Getter(item); | ||
| Assert.Equal(0, time.Millisecond); | ||
| }); | ||
| // OSX HFS driver format does not support millisec granularity | ||
| Assert.All(TimeFunctions(), (function) => | ||
| { | ||
| DateTime time = function.Getter(item); | ||
| Assert.Equal(0, time.Millisecond); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| protected void ValidateSetTimes(T item, DateTime beforeTime, DateTime afterTime) | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Style nit, sometimes
!(A && B)is easier to read than!A || !B. In this case I read "if it's not Mac or it's not HFS" whereas what a human would say is "if it's not HFS on Mac" so I believemay be easier to read.
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.
No need to go back to fix, just general observation