Imported Upstream version 5.2.0.175

Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-06-07 13:16:24 +00:00
parent 4bdbaf4a88
commit 966bba02bb
8776 changed files with 346420 additions and 149650 deletions

View File

@@ -9,6 +9,7 @@ namespace System.IO.Tests
public class RenamedEventArgsTests
{
[Theory]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "OldFullPath on Desktop demands FileIOPermissions which causes failures for invalid paths.")]
[InlineData(WatcherChangeTypes.Changed, "C:", "foo.txt", "bar.txt")]
[InlineData(WatcherChangeTypes.All, "C:", "foo.txt", "bar.txt")]
[InlineData(0, "", "", "")]

View File

@@ -2,9 +2,6 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard1.3-Linux;
netstandard1.3-OSX;
netstandard1.3-Windows_NT;
netstandard-Linux;
netstandard-OSX;
netstandard-Windows_NT;

View File

@@ -9,7 +9,7 @@ namespace System.IO.Tests
public class Directory_Move_Tests : FileSystemWatcherTest
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Directory_Move_To_Same_Directory()
{
DirectoryMove_SameDirectory(WatcherChangeTypes.Renamed);
@@ -22,14 +22,14 @@ namespace System.IO.Tests
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Windows_Directory_Move_To_Different_Watched_Directory()
{
DirectoryMove_DifferentWatchedDirectory(WatcherChangeTypes.Changed);
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Expected WatcherChangeTypes are different based on OS
public void Unix_Directory_Move_To_Different_Watched_Directory()
{
DirectoryMove_DifferentWatchedDirectory(0);

View File

@@ -142,7 +142,7 @@ namespace System.IO.Tests
[Theory]
[MemberData(nameof(FilterTypes))]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Uses P/Invokes to set security info
public void FileSystemWatcher_Directory_NotifyFilter_Security(NotifyFilters filter)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))

View File

@@ -9,14 +9,14 @@ namespace System.IO.Tests
public class File_Move_Tests : FileSystemWatcherTest
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Windows_File_Move_To_Same_Directory()
{
FileMove_SameDirectory(WatcherChangeTypes.Renamed);
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Expected WatcherChangeTypes are different based on OS
public void Unix_File_Move_To_Same_Directory()
{
FileMove_SameDirectory(WatcherChangeTypes.Created | WatcherChangeTypes.Deleted);
@@ -29,21 +29,21 @@ namespace System.IO.Tests
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Windows_File_Move_To_Different_Watched_Directory()
{
FileMove_DifferentWatchedDirectory(WatcherChangeTypes.Changed);
}
[Fact]
[PlatformSpecific(TestPlatforms.OSX)]
[PlatformSpecific(TestPlatforms.OSX)] // Expected WatcherChangeTypes are different based on OS
public void OSX_File_Move_To_Different_Watched_Directory()
{
FileMove_DifferentWatchedDirectory(WatcherChangeTypes.Changed);
}
[Fact]
[PlatformSpecific(TestPlatforms.Linux)]
[PlatformSpecific(TestPlatforms.Linux)] // Expected WatcherChangeTypes are different based on OS
public void Linux_File_Move_To_Different_Watched_Directory()
{
FileMove_DifferentWatchedDirectory(0);
@@ -58,7 +58,7 @@ namespace System.IO.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Windows_File_Move_In_Nested_Directory(bool includeSubdirectories)
{
FileMove_NestedDirectory(includeSubdirectories ? WatcherChangeTypes.Renamed : 0, includeSubdirectories);
@@ -67,21 +67,21 @@ namespace System.IO.Tests
[Theory]
[InlineData(false)]
[InlineData(true)]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Expected WatcherChangeTypes are different based on OS
public void Unix_File_Move_In_Nested_Directory(bool includeSubdirectories)
{
FileMove_NestedDirectory(includeSubdirectories ? WatcherChangeTypes.Created | WatcherChangeTypes.Deleted : 0, includeSubdirectories);
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Expected WatcherChangeTypes are different based on OS
public void Windows_File_Move_With_Set_NotifyFilter()
{
FileMove_WithNotifyFilter(WatcherChangeTypes.Renamed);
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Expected WatcherChangeTypes are different based on OS
public void Unix_File_Move_With_Set_NotifyFilter()
{
FileMove_WithNotifyFilter(WatcherChangeTypes.Deleted);

View File

@@ -169,7 +169,7 @@ namespace System.IO.Tests
[Theory]
[MemberData(nameof(FilterTypes))]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Uses P/Invokes to set security info
public void FileSystemWatcher_File_NotifyFilter_Security(NotifyFilters filter)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))

View File

@@ -41,7 +41,7 @@ namespace System.IO.Tests
[Theory]
[InlineData(true)]
[InlineData(false)]
[PlatformSpecific(TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.Windows)] // Uses P/Invokes
public void FileSystemWatcher_InternalBufferSize(bool setToHigherCapacity)
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))

View File

@@ -125,7 +125,6 @@ namespace System.IO.Tests
}
[Theory]
[OuterLoop("This test has a longer than average timeout and may fail intermittently")]
[InlineData(WatcherChangeTypes.Created)]
[InlineData(WatcherChangeTypes.Deleted)]
public void CreatedDeleted_Success(WatcherChangeTypes changeType)
@@ -133,76 +132,107 @@ namespace System.IO.Tests
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var fsw = new FileSystemWatcher(testDirectory.Path))
{
Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(changeType, LongWaitTimeout));
while (!t.IsCompleted)
for (int i = 1; i <= DefaultAttemptsForExpectedEvent; i++)
{
string path = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.WriteAllText(path, "text");
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
if ((changeType & WatcherChangeTypes.Deleted) != 0)
Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(changeType, WaitForExpectedEventTimeout));
while (!t.IsCompleted)
{
File.Delete(path);
string path = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.WriteAllText(path, "text");
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
if ((changeType & WatcherChangeTypes.Deleted) != 0)
{
File.Delete(path);
}
}
}
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.Equal(changeType, t.Result.ChangeType);
Assert.NotNull(t.Result.Name);
Assert.Null(t.Result.OldName);
Assert.False(t.Result.TimedOut);
try
{
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.Equal(changeType, t.Result.ChangeType);
Assert.NotNull(t.Result.Name);
Assert.Null(t.Result.OldName);
Assert.False(t.Result.TimedOut);
}
catch when (i < DefaultAttemptsForExpectedEvent)
{
continue;
}
return;
}
}
}
[Fact]
[OuterLoop("This test has a longer than average timeout and may fail intermittently")]
public void Changed_Success()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var fsw = new FileSystemWatcher(testDirectory.Path))
{
string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Create(name).Dispose();
Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(WatcherChangeTypes.Changed, LongWaitTimeout));
while (!t.IsCompleted)
for (int i = 1; i <= DefaultAttemptsForExpectedEvent; i++)
{
File.AppendAllText(name, "text");
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
}
string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Create(name).Dispose();
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.Equal(WatcherChangeTypes.Changed, t.Result.ChangeType);
Assert.NotNull(t.Result.Name);
Assert.Null(t.Result.OldName);
Assert.False(t.Result.TimedOut);
Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(WatcherChangeTypes.Changed, WaitForExpectedEventTimeout));
while (!t.IsCompleted)
{
File.AppendAllText(name, "text");
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
}
try
{
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.Equal(WatcherChangeTypes.Changed, t.Result.ChangeType);
Assert.NotNull(t.Result.Name);
Assert.Null(t.Result.OldName);
Assert.False(t.Result.TimedOut);
}
catch when (i < DefaultAttemptsForExpectedEvent)
{
continue;
}
return;
}
}
}
[Fact]
[OuterLoop("This test has a longer than average timeout and may fail intermittently")]
public void Renamed_Success()
{
using (var testDirectory = new TempDirectory(GetTestFilePath()))
using (var fsw = new FileSystemWatcher(testDirectory.Path))
{
Task<WaitForChangedResult> t = Task.Run(() =>
fsw.WaitForChanged(WatcherChangeTypes.Renamed | WatcherChangeTypes.Created, LongWaitTimeout)); // on some OSes, the renamed might come through as Deleted/Created
string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Create(name).Dispose();
while (!t.IsCompleted)
for (int i = 1; i <= DefaultAttemptsForExpectedEvent; i++)
{
string newName = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Move(name, newName);
name = newName;
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
}
Task<WaitForChangedResult> t = Task.Run(() =>
fsw.WaitForChanged(WatcherChangeTypes.Renamed | WatcherChangeTypes.Created, WaitForExpectedEventTimeout)); // on some OSes, the renamed might come through as Deleted/Created
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.True(t.Result.ChangeType == WatcherChangeTypes.Created || t.Result.ChangeType == WatcherChangeTypes.Renamed);
Assert.NotNull(t.Result.Name);
Assert.False(t.Result.TimedOut);
string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Create(name).Dispose();
while (!t.IsCompleted)
{
string newName = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
File.Move(name, newName);
name = newName;
Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
}
try
{
Assert.Equal(TaskStatus.RanToCompletion, t.Status);
Assert.True(t.Result.ChangeType == WatcherChangeTypes.Created || t.Result.ChangeType == WatcherChangeTypes.Renamed);
Assert.NotNull(t.Result.Name);
Assert.False(t.Result.TimedOut);
}
catch when (i < DefaultAttemptsForExpectedEvent)
{
continue;
}
return;
}
}
}

View File

@@ -369,7 +369,7 @@ namespace System.IO.Tests
}
[Fact]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.Windows)]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.Windows)] // Casing matters on Linux
public void FileSystemWatcher_OnCreatedWithMismatchedCasingGivesExpectedFullPath()
{
using (var dir = new TempDirectory(GetTestFilePath()))
@@ -551,7 +551,7 @@ namespace System.IO.Tests
}
[Fact]
[PlatformSpecific(TestPlatforms.Linux)]
[PlatformSpecific(TestPlatforms.Linux)] // Reads MaxUsersWatches from Linux OS files
[OuterLoop("This test has high system resource demands and may cause failures in other concurrent tests")]
public void FileSystemWatcher_CreateManyConcurrentWatches()
{

View File

@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<OSGroup>Linux</OSGroup>
</Project>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<OSGroup>OSX</OSGroup>
</Project>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<OSGroup>Windows_NT</OSGroup>
</Project>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<OSGroup>Linux</OSGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<OSGroup>OSX</OSGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.IO.FileSystem.Watcher.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<OSGroup>Windows_NT</OSGroup>
<TestTFMs>netcoreapp1.0;net46</TestTFMs>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -1,22 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{20411A66-C7A4-4941-8FA2-66308365FD22}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Linux-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Linux-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-OSX-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-OSX-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Linux-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Linux-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-OSX-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-OSX-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Windows_NT-Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Linux-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Linux-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-OSX-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-OSX-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="FileSystemWatcher.netstandard.cs" />
<Compile Include="InternalBufferOverflowException.cs" />
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
@@ -59,4 +53,4 @@
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@@ -328,10 +328,10 @@ namespace System.IO.Tests
Thread.Sleep(500);
}
AutoResetEvent errorOccured = new AutoResetEvent(false);
AutoResetEvent errorOccurred = new AutoResetEvent(false);
watcher.Error += (o, e) =>
{
errorOccured.Set();
errorOccurred.Set();
};
// Enable raising events but be careful with the possibility of the max user inotify instances being reached already.
@@ -352,7 +352,7 @@ namespace System.IO.Tests
}
action();
result = errorOccured.WaitOne(WaitForExpectedEventTimeout);
result = errorOccurred.WaitOne(WaitForExpectedEventTimeout);
watcher.EnableRaisingEvents = false;
cleanup();
}