Skip to content

Commit

Permalink
Code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Apr 20, 2024
1 parent d91a6fd commit 9f80d34
Showing 1 changed file with 180 additions and 0 deletions.
180 changes: 180 additions & 0 deletions AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,186 @@ async Task<double> Factorial(int number, bool isFirst = true)
Assert.Equal(120, await Factorial(5));
}

[Fact]
public void TestRecursionWithCancellationToken()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

double Factorial(int number, bool isFirst = true)
{
using (asyncKeyedLocker.ConditionalLock("test123", isFirst, new CancellationToken(false)))
{
if (number == 0)
return 1;
return number * Factorial(number - 1, false);
}
}

Assert.Equal(120, Factorial(5));
}

[Fact]
public async Task TestRecursionWithCancellationTokenAsync()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

async Task<double> Factorial(int number, bool isFirst = true)
{
using (await asyncKeyedLocker.ConditionalLockAsync("test123", isFirst, new CancellationToken(false)))
{
if (number == 0)
return 1;
return number * await Factorial(number - 1, false);
}
}

Assert.Equal(120, await Factorial(5));
}

[Fact]
public void TestRecursionWithTimeout()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

double Factorial(int number, bool isFirst = true)
{
using (asyncKeyedLocker.ConditionalLock("test123", isFirst, Timeout.Infinite, out _))
{
if (number == 0)
return 1;
return number * Factorial(number - 1, false);
}
}

Assert.Equal(120, Factorial(5));
}

[Fact]
public async Task TestRecursionWithTimeoutAsync()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

async Task<double> Factorial(int number, bool isFirst = true)
{
using (await asyncKeyedLocker.ConditionalLockAsync("test123", isFirst, Timeout.Infinite))
{
if (number == 0)
return 1;
return number * await Factorial(number - 1, false);
}
}

Assert.Equal(120, await Factorial(5));
}

[Fact]
public void TestRecursionWithTimeSpan()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

double Factorial(int number, bool isFirst = true)
{
using (asyncKeyedLocker.ConditionalLock("test123", isFirst, TimeSpan.Zero, out _))
{
if (number == 0)
return 1;
return number * Factorial(number - 1, false);
}
}

Assert.Equal(120, Factorial(5));
}

[Fact]
public async Task TestRecursionWithTimeSpanAsync()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

async Task<double> Factorial(int number, bool isFirst = true)
{
using (await asyncKeyedLocker.ConditionalLockAsync("test123", isFirst, TimeSpan.Zero))
{
if (number == 0)
return 1;
return number * await Factorial(number - 1, false);
}
}

Assert.Equal(120, await Factorial(5));
}

[Fact]
public void TestRecursionWithTimeoutAndCancellationToken()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

double Factorial(int number, bool isFirst = true)
{
using (asyncKeyedLocker.ConditionalLock("test123", isFirst, Timeout.Infinite, new CancellationToken(false), out _))
{
if (number == 0)
return 1;
return number * Factorial(number - 1, false);
}
}

Assert.Equal(120, Factorial(5));
}

[Fact]
public async Task TestRecursionWithTimeoutAndCancellationTokenAsync()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

async Task<double> Factorial(int number, bool isFirst = true)
{
using (await asyncKeyedLocker.ConditionalLockAsync("test123", isFirst, Timeout.Infinite, new CancellationToken(false)))
{
if (number == 0)
return 1;
return number * await Factorial(number - 1, false);
}
}

Assert.Equal(120, await Factorial(5));
}

[Fact]
public void TestRecursionWithTimeSpanAndCancellationToken()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

double Factorial(int number, bool isFirst = true)
{
using (asyncKeyedLocker.ConditionalLock("test123", isFirst, TimeSpan.Zero, new CancellationToken(false), out _))
{
if (number == 0)
return 1;
return number * Factorial(number - 1, false);
}
}

Assert.Equal(120, Factorial(5));
}

[Fact]
public async Task TestRecursionWithTimeSpanAndCancellationTokenAsync()
{
var asyncKeyedLocker = new AsyncKeyedLocker<string>(o => o.PoolSize = 1);

async Task<double> Factorial(int number, bool isFirst = true)
{
using (await asyncKeyedLocker.ConditionalLockAsync("test123", isFirst, TimeSpan.Zero, new CancellationToken(false)))
{
if (number == 0)
return 1;
return number * await Factorial(number - 1, false);
}
}

Assert.Equal(120, await Factorial(5));
}

[Fact]
public void IsInUseRaceConditionCoverage()
{
Expand Down

0 comments on commit 9f80d34

Please sign in to comment.