Skip to content
Discussion options

You must be logged in to vote

The issue here isn't necessarily a bug in FakeTimeProvider, but a synchronization conflict between the AutoAdvanceAmount and the manual Advance() call inside an async callback.

When you use AutoAdvanceAmount, the clock moves immediately when the timer checks the time. If you also call timeProvider.Advance(period * 2) inside the action, you are moving the target "wakeup time" further away while the PeriodicTimer is still trying to process the current state.

The Clean Senior Approach:

To test PeriodicTimer reliably with FakeTimeProvider, you should avoid AutoAdvanceAmount if you intend to control the ticks manually for assertions. Here is how to refactor your test to make it deterministic:

[…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lilinus
Comment options

@olstakh
Comment options

Comment options

You must be logged in to vote
2 replies
@olstakh
Comment options

@raulmaciasdev
Comment options

Answer selected by olstakh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants