Skip to content

Commit

Permalink
Make FileSystemWatcher tests tolerant of spurious/extra events on all…
Browse files Browse the repository at this point in the history
… platforms. Fixes dotnet/coreclrdotnet/corefx#14154. (dotnet/corefx#24406)

Commit migrated from dotnet/corefx@8665e8b
  • Loading branch information
poizan42 authored and Paulo Janotti committed Oct 3, 2017
1 parent f991f14 commit 58ea9bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace System.IO.Tests
public class File_Create_Tests : FileSystemWatcherTest
{
[Fact]
[ActiveIssue("https://github.com/dotnet/coreclr/issues/14154", TestPlatforms.AnyUnix)]
public void FileSystemWatcher_File_Create()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public void BeginInit_PausesEnableRaisingEvents()
/// EndInit will begin EnableRaisingEvents if we previously set EnableRaisingEvents=true
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/coreclr/issues/14154", TestPlatforms.AnyUnix)]
public void EndInit_ResumesPausedEnableRaisingEvents()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand All @@ -216,7 +215,6 @@ public void EndInit_ResumesPausedEnableRaisingEvents()
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/dotnet/coreclr/issues/14154", TestPlatforms.AnyUnix)]
public void EndInit_ResumesPausedEnableRaisingEvents(bool setBeforeBeginInit)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,14 @@ public static bool ExecuteAndVerifyEvents(FileSystemWatcher watcher, WatcherChan
AutoResetEvent changed = null, created = null, deleted = null, renamed = null;
string[] expectedFullPaths = expectedPaths == null ? null : expectedPaths.Select(e => Path.GetFullPath(e)).ToArray();

// On OSX we get a number of extra events tacked onto valid events. As such, we can not ever confidently
// say that an event won't occur, only that one will occur.
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (verifyChanged = ((expectedEvents & WatcherChangeTypes.Changed) > 0))
changed = WatchChanged(watcher, expectedPaths);
if (verifyCreated = ((expectedEvents & WatcherChangeTypes.Created) > 0))
created = WatchCreated(watcher, expectedPaths);
if (verifyDeleted = ((expectedEvents & WatcherChangeTypes.Deleted) > 0))
deleted = WatchDeleted(watcher, expectedPaths);
if (verifyRenamed = ((expectedEvents & WatcherChangeTypes.Renamed) > 0))
renamed = WatchRenamed(watcher, expectedPaths);
}
else
{
changed = WatchChanged(watcher, (expectedEvents & WatcherChangeTypes.Changed) > 0 ? expectedPaths : null);
created = WatchCreated(watcher, (expectedEvents & WatcherChangeTypes.Created) > 0 ? expectedPaths : null);
deleted = WatchDeleted(watcher, (expectedEvents & WatcherChangeTypes.Deleted) > 0 ? expectedPaths : null);
renamed = WatchRenamed(watcher, (expectedEvents & WatcherChangeTypes.Renamed) > 0 ? expectedPaths : null);
}
if (verifyChanged = ((expectedEvents & WatcherChangeTypes.Changed) > 0))
changed = WatchChanged(watcher, expectedPaths);
if (verifyCreated = ((expectedEvents & WatcherChangeTypes.Created) > 0))
created = WatchCreated(watcher, expectedPaths);
if (verifyDeleted = ((expectedEvents & WatcherChangeTypes.Deleted) > 0))
deleted = WatchDeleted(watcher, expectedPaths);
if (verifyRenamed = ((expectedEvents & WatcherChangeTypes.Renamed) > 0))
renamed = WatchRenamed(watcher, expectedPaths);

watcher.EnableRaisingEvents = true;
action();
Expand Down

0 comments on commit 58ea9bf

Please sign in to comment.