Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a31762f

Browse files
jkotasdanmoseley
authored andcommitted
WIP: Enable TimesIncludeMillisecondPart on selected filesystems only (#28242)
* Enable TimesIncludeMillisecondPart on selected filesystems only Use filesystem name to suppress the test failure * Make the test fail * Break out tests
1 parent fcfb556 commit a31762f

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public abstract class BaseGetSetTimes<T> : FileSystemTest
1616
public abstract T GetExistingItem();
1717
public abstract T GetMissingItem();
1818

19+
public abstract string GetItemPath(T item);
20+
1921
public abstract IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false);
2022

2123
public class TimeFunction : Tuple<SetTime, GetTime, DateTimeKind>
@@ -69,8 +71,47 @@ public void CanGetAllTimesAfterCreation()
6971
}
7072

7173
[Fact]
72-
[PlatformSpecific(~TestPlatforms.OSX)] // OSX does not currently support millisec granularity
73-
public void TimesIncludeMillisecondPart()
74+
[PlatformSpecific(TestPlatforms.Linux)] // Windows tested below, and OSX does not currently support millisec granularity
75+
public void TimesIncludeMillisecondPart_Linux()
76+
{
77+
T item = GetExistingItem();
78+
79+
string driveFormat = new DriveInfo(GetItemPath(item)).DriveFormat;
80+
81+
Assert.All(TimeFunctions(), (function) =>
82+
{
83+
var msec = 0;
84+
for (int i = 0; i < 5; i++)
85+
{
86+
DateTime time = function.Getter(item);
87+
msec = time.Millisecond;
88+
89+
//if (msec != 0)
90+
// break;
91+
92+
// This case should only happen 1/1000 times, unless the OS/Filesystem does
93+
// not support millisecond granularity.
94+
95+
// If it's 1/1000, or low granularity, this may help:
96+
Thread.Sleep(1234);
97+
98+
// If it's the OS/Filesystem often returns 0 for the millisecond part, this may
99+
// help prove it. This should only be written 1/1000 runs, unless the test is going to
100+
// fail.
101+
//Console.WriteLine($"TimesIncludeMillisecondPart got a file time of {time.ToString("o")}");
102+
Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}");
103+
104+
item = GetExistingItem(); // try a new file/directory
105+
}
106+
107+
Assert.NotEqual(0, msec);
108+
});
109+
}
110+
111+
112+
[Fact]
113+
[PlatformSpecific(TestPlatforms.Windows)] // Breaking out Windows as it passes no problem there
114+
public void TimesIncludeMillisecondPart_Windows()
74115
{
75116
T item = GetExistingItem();
76117
Assert.All(TimeFunctions(), (function) =>

src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public abstract class StaticGetSetTimes : BaseGetSetTimes<string>
1010
{
1111
public override string GetMissingItem() => GetTestFilePath();
1212

13+
public override string GetItemPath(string item) => item;
14+
1315
[Fact]
1416
public void NullPath_ThrowsArgumentNullException()
1517
{

src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class DirectoryInfo_GetSetTimes : InfoGetSetTimes<DirectoryInfo>
1212

1313
public override DirectoryInfo GetMissingItem() => new DirectoryInfo(GetTestFilePath());
1414

15+
public override string GetItemPath(DirectoryInfo item) => item.FullName;
16+
1517
public override void InvokeCreate(DirectoryInfo item) => item.Create();
1618

1719
public override IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false)

src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public override FileInfo GetExistingItem()
1919

2020
public override FileInfo GetMissingItem() => new FileInfo(GetTestFilePath());
2121

22+
public override string GetItemPath(FileInfo item) => item.FullName;
23+
2224
public override void InvokeCreate(FileInfo item) => item.Create();
2325

2426
public override IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false)

0 commit comments

Comments
 (0)