All notable changes to TimeProviderExtensions will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Upgrade dependencies to none-preview versions.
- Generate strong-named assemblies.
-
Added
ActiveTimersproperty toManualTimeProvider. The property will display the number of currently active timers that have a callback scheduled to be called in the future. -
Allow
ManualTimeProvider.Startto be set using property initializers. -
Made the timer type created by
ManualTimeProvider, theManualTimertype, public, and introduced a protected methodCreateManualTimeronManualTimeProvider. This enables advanced scenarios where a customManualTimeris needed.A custom implementation of
ManualTimercan override theChangemethod and add custom behavior to it.Overriding
CreateManualTimermakes it possible to intercept aTimerCallbackand perform actions before and after the timer callback has been invoked. -
Replace the
AutoAdvanceAmountproperty with theAutoAdvanceBehaviorproperty onManualTimeProvider, and introduce theAutoAdvanceBehaviortype. To automatically advance the time whenGetUtcNow()orGetLocalNow()is called, setAutoAdvanceBehavior.UtcNowAdvanceAmountto aTimeSpanlarger than zero. -
Enable auto advance feature for
GetTimestamp()andGetElapsedTime(long). To automatically advance the time whenGetTimestamp()orGetElapsedTime(long)is called, setAutoAdvanceBehavior.TimestampAdvanceAmountto aTimeSpanlarger than zero. -
ManualTimernow exposes its current configuration.DueTime,Period,IsActive,CallbackTime, andCallbackInvokeCountare now publicly visible. -
Enable auto-advance feature for timers. This enables automatically calling timers callback a specified number of times, by setting the
AutoAdvanceBehavior.TimerAutoTriggerCountproperty to a number larger than zero.
- Updated Microsoft.Bcl.TimeProvider package dependency to rc.1 version.
- Added support for netstandard2.0, as this is supported by the back-port package https://www.nuget.org/packages/Microsoft.Bcl.TimeProvider.
- Added
Jump(TimeSpan)andJump(DateTimeOffset)methods that will jump time to the specified place. Any timer callbacks between the start and end of the jump will be invoked the expected number of times, but the date/time returned fromGetUtcNow()andGetTimestamp()will always be the jump time. This differs from howAdvanceandSetUtcNowworks. See the readme for a detailed description.
Aligned the public API surface of ManualTimeProvider with Microsoft.Extensions.Time.Testing.FakeTimeProvider. This means:
- The
StartTimeproperty is now calledStart. - The
ForwardTimemethod has been removed (useAdvanceinstead). - The
AutoAdvanceAmountproperty has been introduced, which will advance time with the specified amount every timeGetUtcNow()is called. It defaults toTimeSpan.Zero, which disables auto-advancing.
- Added 'StartTime' to
ManualTestProvider, which represents the initial date/time when theManualtTimeProviderwas initialized.
-
Changed
ManualTestProviderto set the local time zone to UTC by default, providing a method for overriding during testing. -
Changed the
ManualTestProvider.ToString()method to return current date time. -
Fixed
ITimerreturned byManualTestProvidersuch that timers created with a due time equal to zero will fire the timer callback immediately.
This release adds a dependency on Microsoft.Bcl.TimeProvider and utilizes the types built-in to that to do much of the work.
When using the ManualTimeProvider during testing, be aware of these outstanding issues: dotnet/runtime#85326
-
Removed
CancelAfterextension methods. Instead, create a CancellationTokenSource via the methodTimeProvider.CreateCancellationTokenSource(TimeSpan delay)or in .NET 8, using `new CancellationTokenSource(TimeSpan delay, TimeProvider timeProvider).NOTE: If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking
CancellationTokenSource.CancelAfter(TimeSpan)on the resultant object. This action will not terminate the initial timer indicated bydelay. However, this restriction does not apply to .NET 8.0 and later versions.
- Added
TimeProvider.GetElapsedTime(long startingTimestamp) - Added
TimeProvider.CreateCancellationTokenSource(TimeSpan delay)
- Add support for libraries that target netstandard 2.0.
- Changed
TestTimeProvidertoManualTimeProvider. ManualTimeProviderno longer implements onIDisposable.- Moving time forward using
ManualTimeProviderwill now move time forward in steps, stopping at each scheduled timer/callback time, setting the internal "UtcNow" clock returned fromGetUtcNow()to invoke the callback, and then progress to the next scheduled timer, until the target "UtcNow" is reached.
- Implemented a shim for the TimeProvider API coming in .NET 8.
- Added support for controlling timestamps during testing.
- Marked the
UtcNowas obsolete.
- Added support for timers.
- Adds support for canceling a
CancellationTokenSourceafter a specific timespan via theITimeScheduler.CancelAfter(CancellationTokenSource, TimeSpan)method. - Adds a singleton instance property to
DefaultSchedulerthat can be used instead of creating a new instance for every use.
- All methods in
DefaultSchedulermarked with the[MethodImpl(MethodImplOptions.AggressiveInlining)]attribute. TestScheduler.ForwardTime(TimeSpan time)throwsArgumentExceptionif thetimeargument is not positive.
Adds support for the Task.WaitAsync family of methods.
Initial release with support for Task.Delay and PeriodicTimer.