Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/System.IO.FileSystem/tests/FileStream/LockUnlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,28 @@ public void FileClosed_Throws()
Assert.Throws<ObjectDisposedException>(() => 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<PlatformNotSupportedException>(() => fs.Lock(0, 100));
File.Open(path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete).Dispose();
Assert.Throws<PlatformNotSupportedException>(() => 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();
Expand All @@ -57,9 +72,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();
Expand Down Expand Up @@ -89,14 +104,14 @@ 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)]
[InlineData(10, 3, 5, 4, 5)]
[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();
Expand All @@ -114,16 +129,15 @@ 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)]
[InlineData(10, 3, 5, 4, 5)]
[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();
Expand All @@ -139,7 +153,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)]
Expand All @@ -148,6 +161,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();
Expand Down