Skip to content

Latest commit

 

History

History
19 lines (13 loc) · 1.56 KB

interval-timer-testing.md

File metadata and controls

19 lines (13 loc) · 1.56 KB

Interval timer (testing) — PrimeTime (NodaTime) stack

These xUnit examples drive interval timers under a virtual PrimeTestClock. Callbacks fire only when the test advances the clock, so the assertions are deterministic and there are no real-world wait times.

[!code-csharp]

What to notice

  • PrimeTestClock is constructed from a NodaTime Instant so the NodaTime stack starts at a known UTC instant without timezone ambiguity.
  • Advance(Duration) moves virtual time forward; callbacks scheduled at or before the new "now" are dispatched synchronously by the test clock before Advance returns.
  • A one-shot timer is requested by passing Timeout.InfiniteTimeSpan as the repeat interval. IClockIntervalTimer.IsRepeating is false for one-shot registrations.
  • For repeating timers, advancing past each multiple of the repeat interval produces one callback per interval crossed.
  • The async overload (RegisterAsyncTimer) completes the awaited callback before Advance returns.

Related