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

Commit a399e51

Browse files
maryamariyandanmoseley
authored andcommitted
Updating test to assert milisecond granularity for (#30763)
- non any linux or - OSX non-HFS driver formats Fixes #30472
1 parent 38b71a3 commit a399e51

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

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

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace System.IO.Tests
1010
{
1111
public abstract class BaseGetSetTimes<T> : FileSystemTest
1212
{
13+
private const string HFS = "hfs";
1314
public delegate void SetTime(T item, DateTime time);
1415
public delegate DateTime GetTime(T item);
1516

@@ -71,40 +72,43 @@ public void CanGetAllTimesAfterCreation()
7172
}
7273

7374
[Fact]
74-
[PlatformSpecific(TestPlatforms.Linux)] // Windows tested below, and OSX does not currently support millisec granularity
75-
public void TimesIncludeMillisecondPart_Linux()
75+
[PlatformSpecific(TestPlatforms.AnyUnix)] // Windows tested below, and OSX HFS driver format does not support millisec granularity
76+
public void TimesIncludeMillisecondPart_Unix()
7677
{
7778
T item = GetExistingItem();
7879

7980
string driveFormat = new DriveInfo(GetItemPath(item)).DriveFormat;
80-
81-
Assert.All(TimeFunctions(), (function) =>
81+
if (!PlatformDetection.IsOSX ||
82+
!driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase))
8283
{
83-
var msec = 0;
84-
for (int i = 0; i < 5; i++)
84+
Assert.All(TimeFunctions(), (function) =>
8585
{
86-
DateTime time = function.Getter(item);
87-
msec = time.Millisecond;
86+
var msec = 0;
87+
for (int i = 0; i < 5; i++)
88+
{
89+
DateTime time = function.Getter(item);
90+
msec = time.Millisecond;
8891

89-
if (msec != 0)
90-
break;
92+
if (msec != 0)
93+
break;
9194

92-
// This case should only happen 1/1000 times, unless the OS/Filesystem does
93-
// not support millisecond granularity.
95+
// This case should only happen 1/1000 times, unless the OS/Filesystem does
96+
// not support millisecond granularity.
9497

95-
// If it's 1/1000, or low granularity, this may help:
96-
Thread.Sleep(1234);
98+
// If it's 1/1000, or low granularity, this may help:
99+
Thread.Sleep(1234);
97100

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")} on {driveFormat}");
101+
// If it's the OS/Filesystem often returns 0 for the millisecond part, this may
102+
// help prove it. This should only be written 1/1000 runs, unless the test is going to
103+
// fail.
104+
Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}");
102105

103-
item = GetExistingItem(); // try a new file/directory
104-
}
106+
item = GetExistingItem(); // try a new file/directory
107+
}
105108

106-
Assert.NotEqual(0, msec);
107-
});
109+
Assert.NotEqual(0, msec);
110+
});
111+
}
108112
}
109113

110114

@@ -137,17 +141,20 @@ public void TimesIncludeMillisecondPart_Windows()
137141
}
138142

139143
[Fact]
140-
// OSX does not currently support millisec granularity: use this test as a canary to flag
141-
// if this ever changes so we can enable the actual test
142144
[PlatformSpecific(TestPlatforms.OSX)]
143145
public void TimesIncludeMillisecondPart_OSX()
144146
{
145147
T item = GetExistingItem();
146-
Assert.All(TimeFunctions(), (function) =>
148+
string driveFormat = new DriveInfo(Path.GetTempPath()).DriveFormat;
149+
if (driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase))
147150
{
148-
DateTime time = function.Getter(item);
149-
Assert.Equal(0, time.Millisecond);
150-
});
151+
// OSX HFS driver format does not support millisec granularity
152+
Assert.All(TimeFunctions(), (function) =>
153+
{
154+
DateTime time = function.Getter(item);
155+
Assert.Equal(0, time.Millisecond);
156+
});
157+
}
151158
}
152159

153160
protected void ValidateSetTimes(T item, DateTime beforeTime, DateTime afterTime)

0 commit comments

Comments
 (0)