Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
</PropertyGroup>
<ItemGroup>
<!-- central versions -->
<PackageVersion Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.5.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.10" />
<PackageVersion Include="Aspire.StackExchange.Redis.DistributedCaching" Version="13.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
<PackageVersion Include="RedLock.net" Version="2.3.2" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="NSubstitute" Version="5.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.9.0" />
<PackageVersion Include="NUnit" Version="4.4.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="Testcontainers" Version="4.8.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/DistributedLockManager/DistributedLockManager.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -10,7 +10,7 @@
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Shouldly" />
<PackageReference Include="Testcontainers" />
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DotNet.Testcontainers.Containers;
using NUnit.Framework;
using System.Linq;
using Shouldly;

namespace DistributedLockManager.Tests;

Expand Down Expand Up @@ -68,9 +69,9 @@ public async Task RunWithLockAsync_acquires_and_executes_action()
var service = scope.ServiceProvider.GetRequiredService<IDistributedLockService<bool>>();

var executed = false;
executed = await service.RunWithLockAsync(async () => await SampleAsync(executed), "integration:test:key", CancellationToken.None, expiryInSecond: 5, waitInSecond: 2, retryInSecond: 1);
executed = await service.RunWithLockAsync(SampleAsync, "integration:test:key", CancellationToken.None, expiryInSecond: 5, waitInSecond: 2, retryInSecond: 1);

Assert.IsTrue(executed, "Action should have been executed when lock acquired");
executed.ShouldBeTrue("Action should have been executed when lock acquired");
}

[Test, Order(2)]
Expand Down Expand Up @@ -108,13 +109,12 @@ async Task<bool> CriticalSection()
await Task.WhenAll(tasks);

// Only one should ever be in the critical section at a time
Assert.LessOrEqual(maxConcurrent, 1, $"Expected no concurrent executions, but saw {maxConcurrent}");
Assert.IsTrue(tasks.All(t => t.Result), "All tasks should complete successfully");
maxConcurrent.ShouldBeLessThanOrEqualTo(1, $"Expected no concurrent executions, but saw {maxConcurrent}");
tasks.All(t => t.Result).ShouldBeTrue("All tasks should complete successfully");
}

private static async Task<bool> SampleAsync(bool executed)
private static async Task<bool> SampleAsync()
{
executed = true;
return await Task.FromResult(executed);
return await Task.FromResult(true);
}
}