Skip to content

Commit

Permalink
Code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Dec 30, 2023
1 parent 2fc35e1 commit abb7d24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ public void TestTimeoutWithZeroTimeSpanAndCancelledToken()
asyncKeyedLocker.IsInUse("test").Should().BeFalse();
}

[Fact]
public void TestTimeoutTryLock()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>();
using (asyncKeyedLocker.Lock("test"))
{
Assert.True(asyncKeyedLocker.IsInUse("test"));
Assert.False(asyncKeyedLocker.TryLock("test", () => { }, 0, CancellationToken.None));
Assert.False(asyncKeyedLocker.TryLock("test", () => { }, TimeSpan.Zero, CancellationToken.None));
}
Assert.False(asyncKeyedLocker.IsInUse("test"));
}

[Fact]
public async Task BasicTest()
{
Expand Down
22 changes: 19 additions & 3 deletions AsyncKeyedLock.Tests/StripedAsyncKeyedLocker/OriginalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task TestTimeoutBasic()
public void TestTimeoutBasicWithOutParameter()
{
var asyncKeyedLocker = new StripedAsyncKeyedLocker<string>();
using (var myLock = asyncKeyedLocker.Lock("test", 0, out var entered))
using (var myLock = asyncKeyedLocker.Lock("test", 0, out bool entered))
{
Assert.True(entered);
Assert.True(asyncKeyedLocker.IsInUse("test"));
Expand All @@ -89,7 +89,7 @@ public void TestTimeoutBasicWithOutParameter()
public async Task TestTimeout()
{
var asyncKeyedLocker = new StripedAsyncKeyedLocker<string>();
using (await asyncKeyedLocker.LockAsync("test"))
using (await asyncKeyedLocker.LockAsync("test", 0))
{
using (var myLock = await asyncKeyedLocker.LockAsync("test", 0))
{
Expand All @@ -102,11 +102,27 @@ public async Task TestTimeout()

[Fact]
public void TestTimeoutWithTimeSpanSynchronous()
{
var asyncKeyedLocker = new StripedAsyncKeyedLocker<string>();
using (asyncKeyedLocker.Lock("test", TimeSpan.Zero, out bool entered))
{
Assert.True(entered);
using (asyncKeyedLocker.Lock("test", TimeSpan.Zero, out entered))
{
Assert.False(entered);
}
Assert.True(asyncKeyedLocker.IsInUse("test"));
}
Assert.False(asyncKeyedLocker.IsInUse("test"));
}

[Fact]
public void TestTimeoutWithTimeoutSynchronous()
{
var asyncKeyedLocker = new StripedAsyncKeyedLocker<string>();
using (asyncKeyedLocker.Lock("test"))
{
using (asyncKeyedLocker.Lock("test", TimeSpan.Zero, out bool entered))
using (asyncKeyedLocker.Lock("test", 0, out bool entered))
{
Assert.False(entered);
}
Expand Down

0 comments on commit abb7d24

Please sign in to comment.