making the milisecond test deterministic (dotnet/corefx#34734)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Tue, 22 Jan 2019 17:22:44 +0000 (09:22 -0800)
committerStephen Toub <stoub@microsoft.com>
Tue, 22 Jan 2019 17:22:44 +0000 (12:22 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/673e1c171b95eeb0c23c980bd97aaf9b4f580ab9

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

index 60124f8..e281049 100644 (file)
@@ -23,17 +23,13 @@ namespace System.IO.Tests
         public FileInfo GetNonZeroMilliseconds()
         {
             FileInfo fileinfo = new FileInfo(GetTestFilePath());
-            for (int i = 0; i < 5; i++)
-            {
-                fileinfo.Create().Dispose();
-                if (fileinfo.LastWriteTime.Millisecond != 0)
-                    break;
-
-                // This case should only happen 1/1000 times, unless the OS/Filesystem does
-                // not support millisecond granularity.
+            fileinfo.Create().Dispose();
 
-                // If it's 1/1000, or low granularity, this may help:
-                Thread.Sleep(1234);
+            if (fileinfo.LastWriteTime.Millisecond == 0)
+            {
+                DateTime dt = fileinfo.LastWriteTime;
+                dt = dt.AddMilliseconds(1);
+                fileinfo.LastWriteTime = dt;
             }
 
             Assert.NotEqual(0, fileinfo.LastWriteTime.Millisecond);