dotnet / dotnet/extensions

[API Proposal]: FakeTimeProvider.Advance

Open
#6,404 1 comment 0 reactions 0 assignees View on GitHub
api-suggestion area-fundamentals untriaged
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Background and motivation

Currently, FakeTimeProvider.Advance(); returns a void.

When called, it runs all callbacks, for instance continuations of a PeriodicTimer.WaitForNextTickAsync();
However, as soon as these callback hits an await keyword, the thread jumps to the next waiter.
The rest of the calblacks eventually execute, but there is no reliable way to wait for their completion.
I think these waiters should be returned as a Task.WhenAll() awaitable from Advance();

### API Proposal

```csharp
namespace Microsoft.Extensions.Time.Testing;

public class FakeTimeProvider : TimeProvider
{
public Task Advance(TimeSpan delta);
}
```

### API Usage

```csharp
[Fact]
public async Task GivenCreatedTransaction_StatusIsAbortedAfterTimeout()
{
using var client = application.factory.CreateClient().WithAuthenticationAsParkingService();
var transaction = await client.CreateTransaction().AsTransactionDto();

await application.TimeProvider.Advance(application.PaymentOptions.TransactionLifetime!.Value);

var actual = await client!.GetTransaction(transaction!.Guid).AsTransactionDto();
Assert.Equal(TransactionState.Aborted.ToString(), actual!.State);
}
```

### Alternative Designs

_No response_

### Risks

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.