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

Commit 1ddfc6d

Browse files
committed
Merge pull request #2655 from nguerrera/fix-fsw-linux-test
Fix FileSystemWatcher test race and allow process exit time == start time
2 parents 6b2d600 + 7a083a6 commit 1ddfc6d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/ProcessTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void TestExitTime()
137137
Assert.Throws<InvalidOperationException>(() => p.ExitTime);
138138
p.Kill();
139139
Assert.True(p.WaitForExit(WaitInMS));
140-
Assert.True(p.ExitTime.ToUniversalTime() > timeBeforeProcessStart, "TestExitTime is incorrect.");
140+
Assert.True(p.ExitTime.ToUniversalTime() >= timeBeforeProcessStart, "TestExitTime is incorrect.");
141141
}
142142

143143
[Fact]

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Created.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Runtime.InteropServices;
78
using System.Threading;
89
using Xunit;
910

@@ -101,7 +102,14 @@ public static void FileSystemWatcher_Created_Negative()
101102
testFile.Flush();
102103

103104
// renaming a directory
104-
testDir.Move(testDir.Path + "_rename");
105+
//
106+
// We don't do this on Linux because depending on the timing of MOVED_FROM and MOVED_TO events,
107+
// a rename can trigger delete + create as a deliberate handling of an edge case, and this
108+
// test is checking that no create events are raised.
109+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
110+
{
111+
testDir.Move(testDir.Path + "_rename");
112+
}
105113

106114
// deleting a file & directory by leaving the using block
107115
}

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Deleted.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Runtime.InteropServices;
67
using System.Threading;
78
using Xunit;
89

@@ -70,9 +71,16 @@ public static void FileSystemWatcher_Deleted_Negative()
7071
testFile.Flush();
7172

7273
// renaming a directory
73-
testDir.Move(testDir.Path + "_rename");
74+
//
75+
// We don't do this on Linux because depending on the timing of MOVED_FROM and MOVED_TO events,
76+
// a rename can trigger delete + create as a deliberate handling of an edge case, and this
77+
// test is checking that no delete events are raised.
78+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
79+
{
80+
testDir.Move(testDir.Path + "_rename");
81+
}
7482

75-
Utility.ExpectNoEvent(eventOccured, "changed");
83+
Utility.ExpectNoEvent(eventOccured, "deleted");
7684
}
7785
}
7886
}

0 commit comments

Comments
 (0)