Skip to content
Tracon

StoreCancellationContract<TStore\>

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

The promise every store makes about a token that is already cancelled, plus the lifecycle plumbing every store contract shares.

public abstract class StoreCancellationContract<TStore> : IAsyncLifetime, IAsyncDisposable
Type Parameters
TStore The store type under test.
Inheritance
object ← StoreCancellationContract<TStore>
Implements
IAsyncLifetime, IAsyncDisposable
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

A store handed a token that is already cancelled throws OperationCanceledException and leaves no trace. The write side is the half that matters: throwing on its own proves nothing, because a check placed after the work throws too. The contract therefore reads the store back and requires it to be untouched.

Cancellation during a call is deliberately outside this contract. It races, so no deterministic case can assert where the work stopped. Only a token that was already cancelled when the call started is covered.

Storage.TenantIsolationContract derives from this class and wires the three hooks to its own seed and count hooks, so a tenant-aware store contract implements nothing extra. The four store contracts that carry no tenant dimension derive from this class directly.

protected StoreCancellationContract()

The store under test.

protected TStore Store { get; }

TStore

[Fact]
public Task Canceled_token_throws_on_read()

Task

Canceled_token_throws_on_write_and_leaves_no_trace()

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

Task

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

protected abstract ValueTask CancellableReadAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The token the store must observe.

ValueTask

The completion task; any result is discarded.

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

protected abstract 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.

Produces an empty store for the test.

protected abstract ValueTask<TStore> CreateStoreAsync()

ValueTask<TStore>

A store ready for use.

public ValueTask DisposeAsync()

ValueTask

Called immediately after the class has been created, before it is used.

public ValueTask InitializeAsync()

ValueTask

Hook for a derived class to release its own resources.

protected virtual ValueTask OnDisposeAsync()

ValueTask

A completed task.

The_write_this_contract_checks_can_be_read_back()

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

Task

Reports whether StoreCancellationContract.CancellableWriteAsync left anything behind.

protected abstract ValueTask<bool> WroteAnythingAsync()

ValueTask<bool>

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