HostLoom.Locking.Testing
0.17.0
dotnet add package HostLoom.Locking.Testing --version 0.17.0
NuGet\Install-Package HostLoom.Locking.Testing -Version 0.17.0
<PackageReference Include="HostLoom.Locking.Testing" Version="0.17.0" />
<PackageVersion Include="HostLoom.Locking.Testing" Version="0.17.0" />
<PackageReference Include="HostLoom.Locking.Testing" />
paket add HostLoom.Locking.Testing --version 0.17.0
#r "nuget: HostLoom.Locking.Testing, 0.17.0"
#:package HostLoom.Locking.Testing@0.17.0
#addin nuget:?package=HostLoom.Locking.Testing&version=0.17.0
#tool nuget:?package=HostLoom.Locking.Testing&version=0.17.0
HostLoom.Locking.Testing
Composes a HostLoom.Locking lock for a test without a container, and decorates a provider so a
test can script contention, inject failures, or assert what the lock asked for.
var clock = new FakeTimeProvider();
var provider = new ManualLockProvider(clock);
await using var locks = TestLock.Create(provider: provider, timeProvider: clock);
provider.Hold(TestLock.ProviderKey("job:42")); // another instance owns it
Assert.Null(await locks.TryAcquireAsync("job:42")); // skip-if-busy
provider.Release(TestLock.ProviderKey("job:42"));
TestLock.Create() composes a DistributedLock over the in-process provider with the test
namespace and an immediate, jitter-free retry policy, so a contended acquisition resolves in a
few attempts rather than three seconds. ManualLockProvider is the in-process provider with two
extra verbs, Hold and Release, for the key another instance would own; leases still expire on
the supplied clock, so a lost lease is a clock advance away. FaultingLockProvider fails the next
n calls, or every call, with a chosen LockFailureKind, which is how a test proves a consumer
sees LockProviderUnavailableException rather than a backend exception, and that a release
failure is logged rather than thrown. Its HoldReplies lets acquisitions reach the inner
provider and withholds their answers until DeliverReplies or Heal, with
WaitForHeldReplyAsync signalling that a grant was decided, which is how a test models a reply
that arrives after the caller stopped waiting. RecordingLockProvider records every call with its
outcome, so a test asserts the retry count, the owner token on release, or an extension before
the lease ended.
The in-process provider implements the whole contract, including lease expiry, owner-only release,
and extension, so a consumer's tests need no backend. Time is a TimeProvider everywhere; this
package ships no clock, and Microsoft.Extensions.TimeProvider.Testing provides FakeTimeProvider.
The lock is coordination, not correctness, for persisted state: a test that proves two runs were serialised has proven scheduling, and the database's own constraints still own the invariant.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- HostLoom.Locking (>= 0.17.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.0 | 0 | 10/25/2026 |
| 0.16.1 | 39 | 10/22/2026 |
| 0.16.0 | 84 | 10/14/2026 |
| 0.15.1 | 83 | 10/12/2026 |
| 0.15.0 | 99 | 10/4/2026 |
| 0.14.0 | 93 | 10/4/2026 |
| 0.13.0 | 98 | 9/28/2026 |
| 0.12.0 | 101 | 9/27/2026 |
| 0.11.0 | 101 | 9/25/2026 |
| 0.10.0 | 102 | 9/22/2026 |
| 0.9.0 | 99 | 9/22/2026 |
| 0.8.0 | 104 | 9/19/2026 |
| 0.7.0 | 113 | 9/17/2026 |
| 0.6.0 | 119 | 9/6/2026 |
| 0.5.0 | 149 | 9/5/2026 |
| 0.4.0 | 122 | 9/3/2026 |