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

Commit 56c279d

Browse files
committed
Fix FileSystemWatcher test race + wrong event name
On Linux, depending on the timing of events, we can sometimes generate delete+create instead of rename. As such, we can't perform renames and test that no create or delete is raised when we're running on Linux. The issue had so far only arisen on the negative create test and not the negative delete test, which turned out to be because the negative delete test was using the wrong event name.
1 parent 4c423dc commit 56c279d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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)