Skip to content

FakeTimeProvider.AutoAdvanceAmount doesn't seem to work with Task.Delay #6680

@xdeng-msft

Description

@xdeng-msft

Description

The program would enter an infinite loop when a task delay is created with a FakeTimeProvider with AutoAdvanceAmount configured. I am not entirely sure what's going on, and I tried setting the SynchronizationContext to null & ConfigureAwate(true) but none of them seem to work.

Reproduction Steps

public static async Task Main(string[] args)
{
    FakeTimeProvider timeProvider = new FakeTimeProvider();
    timeProvider.AutoAdvanceAmount = TimeSpan.FromSeconds(10);
    await Task.Delay(TimeSpan.FromSeconds(3), timeProvider);

    await Console.Out.WriteLineAsync("123");
}

Notice that the Console output would never appear as the program is still waiting for the Task.Delay to complete.

Expected behavior

Task.Delay completes immediately as the time provider is configured with an AutoAdvanceAmount that's larger than the delay.

Actual behavior

program waiting for the Task.Delay to complete indefinitely.

Regression?

N/A

Known Workarounds

N/A

Configuration

No response

Other information

Microsoft.Extensions.TimeProvider.Testing 9.7.0 on .net 8

Metadata

Metadata

Assignees

Labels

area-fundamentalsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions