Skip to content

[API Proposal]: FakeTimeProvider.Advance #6404

Open
@ArwynFr

Description

@ArwynFr

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

namespace Microsoft.Extensions.Time.Testing;

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

API Usage

[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions