Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2018-03-21 08:17:25 +0300
committerDan Moseley <danmose@microsoft.com>2018-03-21 08:17:25 +0300
commita31762f7fd5b580a6f583b3bbb69fb9e75b87d14 (patch)
treedaad26796ed5d154c2e0b3c2e3d498e32b9eb991 /src/System.IO.FileSystem/tests
parentfcfb556ebf99ed551c02d0146c805e792b264cf2 (diff)
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
Diffstat (limited to 'src/System.IO.FileSystem/tests')
-rw-r--r--src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs45
-rw-r--r--src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs2
-rw-r--r--src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs2
-rw-r--r--src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs2
4 files changed, 49 insertions, 2 deletions
diff --git a/src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs b/src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs
index e070f6166b..a17fb9bebd 100644
--- a/src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs
+++ b/src/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs
@@ -16,6 +16,8 @@ namespace System.IO.Tests
public abstract T GetExistingItem();
public abstract T GetMissingItem();
+ public abstract string GetItemPath(T item);
+
public abstract IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false);
public class TimeFunction : Tuple<SetTime, GetTime, DateTimeKind>
@@ -69,8 +71,47 @@ namespace System.IO.Tests
}
[Fact]
- [PlatformSpecific(~TestPlatforms.OSX)] // OSX does not currently support millisec granularity
- public void TimesIncludeMillisecondPart()
+ [PlatformSpecific(TestPlatforms.Linux)] // Windows tested below, and OSX does not currently support millisec granularity
+ public void TimesIncludeMillisecondPart_Linux()
+ {
+ T item = GetExistingItem();
+
+ string driveFormat = new DriveInfo(GetItemPath(item)).DriveFormat;
+
+ Assert.All(TimeFunctions(), (function) =>
+ {
+ var msec = 0;
+ for (int i = 0; i < 5; i++)
+ {
+ DateTime time = function.Getter(item);
+ msec = time.Millisecond;
+
+ //if (msec != 0)
+ // break;
+
+ // 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 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")}");
+ Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}");
+
+ item = GetExistingItem(); // try a new file/directory
+ }
+
+ Assert.NotEqual(0, msec);
+ });
+ }
+
+
+ [Fact]
+ [PlatformSpecific(TestPlatforms.Windows)] // Breaking out Windows as it passes no problem there
+ public void TimesIncludeMillisecondPart_Windows()
{
T item = GetExistingItem();
Assert.All(TimeFunctions(), (function) =>
diff --git a/src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs b/src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs
index 6444ff203f..12ee8997fd 100644
--- a/src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs
+++ b/src/System.IO.FileSystem/tests/Base/StaticGetSetTimes.cs
@@ -10,6 +10,8 @@ namespace System.IO.Tests
{
public override string GetMissingItem() => GetTestFilePath();
+ public override string GetItemPath(string item) => item;
+
[Fact]
public void NullPath_ThrowsArgumentNullException()
{
diff --git a/src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs b/src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs
index 927c770d61..779be70df6 100644
--- a/src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs
+++ b/src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs
@@ -12,6 +12,8 @@ namespace System.IO.Tests
public override DirectoryInfo GetMissingItem() => new DirectoryInfo(GetTestFilePath());
+ public override string GetItemPath(DirectoryInfo item) => item.FullName;
+
public override void InvokeCreate(DirectoryInfo item) => item.Create();
public override IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false)
diff --git a/src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs b/src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs
index ed38b89719..d88fa6ea00 100644
--- a/src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs
+++ b/src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs
@@ -19,6 +19,8 @@ namespace System.IO.Tests
public override FileInfo GetMissingItem() => new FileInfo(GetTestFilePath());
+ public override string GetItemPath(FileInfo item) => item.FullName;
+
public override void InvokeCreate(FileInfo item) => item.Create();
public override IEnumerable<TimeFunction> TimeFunctions(bool requiresRoundtripping = false)