Skip to content

Remove CancelAfter and Delay from internal TimeProvider #1348

@martincostello

Description

@martincostello

Attempting to rebase #1144 for .NET 8 and to consume TimeProvider from NuGet (and use the new FakeTimeProvider implementation) things get complicated because there are various tests that rely on TimeProvider having a virtual CancelAfter() and Delay() method that can be overridden in the tests.

// This one is not on TimeProvider, temporarly we need to use it
public virtual Task Delay(TimeSpan delay, CancellationToken cancellationToken = default) => Task.Delay(delay, cancellationToken);
// This one is not on TimeProvider, temporarly we need to use it
public virtual void CancelAfter(CancellationTokenSource source, TimeSpan delay) => source.CancelAfter(delay);

The real implementation instead has extension methods (which we can't mock) which are TimeProvider.Delay() and TimeProvider.CreateCancellationTokenSource().

To make the switch over for .NET 8 simpler, we should sync the current internal implementation to be source compatible with the .NET 8 rather than rely on methods which won't exist. That way, the tests will not need to change much and the switch over should be a lot cleaner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8Issues related to the new version 8 of the Polly library.

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions