Skip to content
Tracon

SingletonLeaseStoreContract

Namespace Tracon.Testing.Contracts.Storage · Assembly Tracon.Testing.Contracts.Xunit.dll

Behavior tests for the ISingletonLeaseStore contract.

public abstract class SingletonLeaseStoreContract : StoreCancellationContract<ISingletonLeaseStore>, IAsyncLifetime, IAsyncDisposable
Inheritance
object ← StoreCancellationContract<ISingletonLeaseStore> ← SingletonLeaseStoreContract
Implements
IAsyncLifetime, IAsyncDisposable
Inherited Members
StoreCancellationContract<ISingletonLeaseStore>.CreateStoreAsync(), StoreCancellationContract<ISingletonLeaseStore>.InitializeAsync(), StoreCancellationContract<ISingletonLeaseStore>.DisposeAsync(), StoreCancellationContract<ISingletonLeaseStore>.OnDisposeAsync(), StoreCancellationContract<ISingletonLeaseStore>.CancellableReadAsync(CancellationToken), StoreCancellationContract<ISingletonLeaseStore>.CancellableWriteAsync(CancellationToken), StoreCancellationContract<ISingletonLeaseStore>.WroteAnythingAsync(), StoreCancellationContract<ISingletonLeaseStore>.Canceled_token_throws_on_read(), StoreCancellationContract<ISingletonLeaseStore>.The_write_this_contract_checks_can_be_read_back(), StoreCancellationContract<ISingletonLeaseStore>.Canceled_token_throws_on_write_and_leaves_no_trace(), StoreCancellationContract<ISingletonLeaseStore>.Store, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

The in-memory store and the three SQL providers must pass the same scenarios. The lease-expiry test runs against real time (a short lease plus a short wait): the SQL implementations do not take their clock from an injectable TimeProvider – the same reason as JobStoreContract.

There is no tenant concept here: single-executor election is a deployment-wide concern. This is why the contract derives from Storage.StoreCancellationContract rather than from Storage.TenantIsolationContract – the same pattern as RetentionStoreContract.

protected SingletonLeaseStoreContract()

Calls one read method of the store with the given token.

protected override ValueTask CancellableReadAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The token the store must observe.

ValueTask

The completion task; any result is discarded.

A lease store has no pure query. Renewing a lease nobody holds is the closest thing to one: it reports false and writes nothing.

Calls one write method of the store with the given token.

protected override ValueTask CancellableWriteAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The token the store must observe.

ValueTask

The completion task.

The write must be one StoreCancellationContract.WroteAnythingAsync can see. A write this contract cannot read back proves nothing about side effects, which is why StoreCancellationContract.The_write_this_contract_checks_can_be_read_back runs the same pair with a live token and requires the read to find it.

[Fact]
public Task Empty_lease_can_be_acquired()

Task

[Fact]
public Task Owner_can_renew_its_lease()

Task

ReleaseAsync_by_a_non_owner_does_nothing()

Section titled “ ReleaseAsync_by_a_non_owner_does_nothing()”
[Fact]
public Task ReleaseAsync_by_a_non_owner_does_nothing()

Task

Released_lease_can_be_reacquired_immediately_by_someone_else()

Section titled “ Released_lease_can_be_reacquired_immediately_by_someone_else()”
[Fact]
public Task Released_lease_can_be_reacquired_immediately_by_someone_else()

Task

RenewAsync_returns_false_for_a_non_owner()

Section titled “ RenewAsync_returns_false_for_a_non_owner()”
[Fact]
public Task RenewAsync_returns_false_for_a_non_owner()

Task

RenewAsync_returns_false_once_the_lease_has_passed_to_someone_else()

Section titled “ RenewAsync_returns_false_once_the_lease_has_passed_to_someone_else()”
[Fact]
public Task RenewAsync_returns_false_once_the_lease_has_passed_to_someone_else()

Task

[Fact]
public Task Same_owner_can_reacquire_its_own_lease()

Task

Second_owner_cannot_acquire_while_lease_is_held()

Section titled “ Second_owner_cannot_acquire_while_lease_is_held()”
[Fact]
public Task Second_owner_cannot_acquire_while_lease_is_held()

Task

Someone_else_can_acquire_once_the_lease_expires()

Section titled “ Someone_else_can_acquire_once_the_lease_expires()”
[Fact]
public Task Someone_else_can_acquire_once_the_lease_expires()

Task

Reports whether StoreCancellationContract.CancellableWriteAsync left anything behind.

protected override ValueTask<bool> WroteAnythingAsync()

ValueTask<bool>

true if the store holds any record the write would have created.

A different owner asks for the same lease. It can only take it if the cancelled call left no row behind.