From 21dd604a2a8d1e76925f01f34849ad442308f28f Mon Sep 17 00:00:00 2001 From: Ian Hays Date: Fri, 24 Feb 2017 13:21:42 -0800 Subject: [PATCH 1/2] Cleanup File Lock/Unlock OSX tests. --- .../tests/FileStream/LockUnlock.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs b/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs index 14521fa935f1..aae7b47f4f98 100644 --- a/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs +++ b/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs @@ -38,13 +38,27 @@ public void FileClosed_Throws() Assert.Throws(() => fs.Lock(0, 1)); } - [ActiveIssue(5964, TestPlatforms.OSX)] + [Fact] + [PlatformSpecific(TestPlatforms.OSX)] + public void LockUnlock_Unsupported_OSX() + { + string path = GetTestFilePath(); + File.WriteAllBytes(path, new byte[100]); + + using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + Assert.Throws(() => fs.Lock(0, 100)); + Assert.Throws(() => fs.Unlock(0, 100)); + } + } + [Theory] [InlineData(100, 0, 100)] [InlineData(200, 0, 100)] [InlineData(200, 50, 150)] [InlineData(200, 100, 100)] [InlineData(20, 2000, 1000)] + [PlatformSpecific(~TestPlatforms.OSX)] public void Lock_Unlock_Successful(long fileLength, long position, long length) { string path = GetTestFilePath(); @@ -57,9 +71,9 @@ public void Lock_Unlock_Successful(long fileLength, long position, long length) } } - [ActiveIssue(5964, TestPlatforms.OSX)] [Theory] [InlineData(10, 0, 2, 3, 5)] + [PlatformSpecific(~TestPlatforms.OSX)] public void NonOverlappingRegions_Success(long fileLength, long firstPosition, long firstLength, long secondPosition, long secondLength) { string path = GetTestFilePath(); @@ -89,7 +103,6 @@ public void NonOverlappingRegions_Success(long fileLength, long firstPosition, l } [Theory] - [PlatformSpecific(TestPlatforms.Windows)] // Unix locks are on a per-process basis, so overlapping locks from the same process are allowed. [InlineData(10, 0, 10, 1, 2)] [InlineData(10, 3, 5, 3, 5)] [InlineData(10, 3, 5, 3, 4)] @@ -97,6 +110,7 @@ public void NonOverlappingRegions_Success(long fileLength, long firstPosition, l [InlineData(10, 3, 5, 2, 6)] [InlineData(10, 3, 5, 2, 4)] [InlineData(10, 3, 5, 4, 6)] + [PlatformSpecific(TestPlatforms.Windows)] // Unix locks are on a per-process basis, so overlapping locks from the same process are allowed. public void OverlappingRegionsFromSameProcess_ThrowsExceptionOnWindows(long fileLength, long firstPosition, long firstLength, long secondPosition, long secondLength) { string path = GetTestFilePath(); @@ -114,9 +128,7 @@ public void OverlappingRegionsFromSameProcess_ThrowsExceptionOnWindows(long file } } - [ActiveIssue(5964, TestPlatforms.OSX)] [Theory] - [PlatformSpecific(TestPlatforms.AnyUnix)] // Unix locks are on a per-process basis, so overlapping locks from the same process are allowed. [InlineData(10, 0, 10, 1, 2)] [InlineData(10, 3, 5, 3, 5)] [InlineData(10, 3, 5, 3, 4)] @@ -124,6 +136,7 @@ public void OverlappingRegionsFromSameProcess_ThrowsExceptionOnWindows(long file [InlineData(10, 3, 5, 2, 6)] [InlineData(10, 3, 5, 2, 4)] [InlineData(10, 3, 5, 4, 6)] + [PlatformSpecific(TestPlatforms.Linux)] // Unix locks are on a per-process basis, so overlapping locks from the same process are allowed. public void OverlappingRegionsFromSameProcess_AllowedOnUnix(long fileLength, long firstPosition, long firstLength, long secondPosition, long secondLength) { string path = GetTestFilePath(); @@ -139,7 +152,6 @@ public void OverlappingRegionsFromSameProcess_AllowedOnUnix(long fileLength, lon } } - [ActiveIssue(5964, TestPlatforms.OSX)] [Theory] [InlineData(10, 0, 10, 1, 2)] [InlineData(10, 3, 5, 3, 5)] @@ -148,6 +160,7 @@ public void OverlappingRegionsFromSameProcess_AllowedOnUnix(long fileLength, lon [InlineData(10, 3, 5, 2, 6)] [InlineData(10, 3, 5, 2, 4)] [InlineData(10, 3, 5, 4, 6)] + [PlatformSpecific(~TestPlatforms.OSX)] public void OverlappingRegionsFromOtherProcess_ThrowsException(long fileLength, long firstPosition, long firstLength, long secondPosition, long secondLength) { string path = GetTestFilePath(); From 79b2895eae0d31872cc348307556e07f9c631a74 Mon Sep 17 00:00:00 2001 From: Ian Hays Date: Fri, 24 Feb 2017 14:28:04 -0800 Subject: [PATCH 2/2] Add fileshare verification to lock/unlock osx test --- src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs b/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs index aae7b47f4f98..76e50b0284b1 100644 --- a/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs +++ b/src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs @@ -48,6 +48,7 @@ public void LockUnlock_Unsupported_OSX() using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { Assert.Throws(() => fs.Lock(0, 100)); + File.Open(path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete).Dispose(); Assert.Throws(() => fs.Unlock(0, 100)); } }