# SingletonLeaseStoreContract

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.testing.contracts.storage.singletonleasestorecontract/
> Summary: SingletonLeaseStoreContract: Behavior tests for the ISingletonLeaseStore contract.

<div class="api-provenance">Namespace Tracon.Testing.Contracts.Storage · Assembly <code>Tracon.Testing.Contracts.Xunit.dll</code></div>

Behavior tests for the [ISingletonLeaseStore](/api/tracon.isingletonleasestore/) contract.

```csharp
public abstract class SingletonLeaseStoreContract : StoreCancellationContract<ISingletonLeaseStore>, IAsyncLifetime, IAsyncDisposable
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/">StoreCancellationContract&lt;ISingletonLeaseStore&gt;</a> ← <a href="/api/tracon.testing.contracts.storage.singletonleasestorecontract/">SingletonLeaseStoreContract</a></dd><dt>Implements</dt><dd>IAsyncLifetime, <a href="https://learn.microsoft.com/dotnet/api/system.iasyncdisposable">IAsyncDisposable</a></dd><dt>Inherited Members</dt><dd><a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_CreateStoreAsync">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.CreateStoreAsync()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_InitializeAsync">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.InitializeAsync()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_DisposeAsync">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.DisposeAsync()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_OnDisposeAsync">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.OnDisposeAsync()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_CancellableReadAsync_System_Threading_CancellationToken_">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.CancellableReadAsync(CancellationToken)</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_CancellableWriteAsync_System_Threading_CancellationToken_">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.CancellableWriteAsync(CancellationToken)</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_WroteAnythingAsync">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.WroteAnythingAsync()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Canceled_token_throws_on_read">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.Canceled_token_throws_on_read()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_The_write_this_contract_checks_can_be_read_back">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.The_write_this_contract_checks_can_be_read_back()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Canceled_token_throws_on_write_and_leaves_no_trace">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.Canceled_token_throws_on_write_and_leaves_no_trace()</a>, <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/#Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Store">StoreCancellationContract&lt;ISingletonLeaseStore&gt;.Store</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

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](https://learn.microsoft.com/dotnet/api/system.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](/api/tracon.testing.contracts.storage/) rather than from
[Storage.TenantIsolationContract](/api/tracon.testing.contracts.storage/) -- the same pattern as
`RetentionStoreContract`.

## Constructors

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract__ctor"></a> SingletonLeaseStoreContract\(\)

```csharp
protected SingletonLeaseStoreContract()
```

## Methods

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_CancellableReadAsync_System_Threading_CancellationToken_"></a> CancellableReadAsync\(CancellationToken\)

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

```csharp
protected override ValueTask CancellableReadAsync(CancellationToken cancellationToken)
```

#### Parameters

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The token the store must observe.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task; any result is discarded.

#### Remarks

A lease store has no pure query. Renewing a lease nobody holds is the
closest thing to one: it reports [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) and writes
nothing.

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_CancellableWriteAsync_System_Threading_CancellationToken_"></a> CancellableWriteAsync\(CancellationToken\)

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

```csharp
protected override ValueTask CancellableWriteAsync(CancellationToken cancellationToken)
```

#### Parameters

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The token the store must observe.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task.

#### Remarks

The write must be one [StoreCancellationContract.WroteAnythingAsync](/api/tracon.testing.contracts.storage/) 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](/api/tracon.testing.contracts.storage/)
runs the same pair with a live token and requires the read to find it.

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Empty_lease_can_be_acquired"></a> Empty\_lease\_can\_be\_acquired\(\)

```csharp
[Fact]
public Task Empty_lease_can_be_acquired()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Owner_can_renew_its_lease"></a> Owner\_can\_renew\_its\_lease\(\)

```csharp
[Fact]
public Task Owner_can_renew_its_lease()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_ReleaseAsync_by_a_non_owner_does_nothing"></a> ReleaseAsync\_by\_a\_non\_owner\_does\_nothing\(\)

```csharp
[Fact]
public Task ReleaseAsync_by_a_non_owner_does_nothing()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Released_lease_can_be_reacquired_immediately_by_someone_else"></a> Released\_lease\_can\_be\_reacquired\_immediately\_by\_someone\_else\(\)

```csharp
[Fact]
public Task Released_lease_can_be_reacquired_immediately_by_someone_else()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_RenewAsync_returns_false_for_a_non_owner"></a> RenewAsync\_returns\_false\_for\_a\_non\_owner\(\)

```csharp
[Fact]
public Task RenewAsync_returns_false_for_a_non_owner()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_RenewAsync_returns_false_once_the_lease_has_passed_to_someone_else"></a> RenewAsync\_returns\_false\_once\_the\_lease\_has\_passed\_to\_someone\_else\(\)

```csharp
[Fact]
public Task RenewAsync_returns_false_once_the_lease_has_passed_to_someone_else()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Same_owner_can_reacquire_its_own_lease"></a> Same\_owner\_can\_reacquire\_its\_own\_lease\(\)

```csharp
[Fact]
public Task Same_owner_can_reacquire_its_own_lease()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Second_owner_cannot_acquire_while_lease_is_held"></a> Second\_owner\_cannot\_acquire\_while\_lease\_is\_held\(\)

```csharp
[Fact]
public Task Second_owner_cannot_acquire_while_lease_is_held()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_Someone_else_can_acquire_once_the_lease_expires"></a> Someone\_else\_can\_acquire\_once\_the\_lease\_expires\(\)

```csharp
[Fact]
public Task Someone_else_can_acquire_once_the_lease_expires()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_SingletonLeaseStoreContract_WroteAnythingAsync"></a> WroteAnythingAsync\(\)

Reports whether [StoreCancellationContract.CancellableWriteAsync](/api/tracon.testing.contracts.storage/) left anything
behind.

```csharp
protected override ValueTask<bool> WroteAnythingAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the store holds any record the write would have created.

#### Remarks

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