Skip to content

Introduce TimeProvider in place of DateTimeHandler#344

Open
JanHyka wants to merge 2 commits into
aws:devfrom
JanHyka:janhyka/testing_phase_1
Open

Introduce TimeProvider in place of DateTimeHandler#344
JanHyka wants to merge 2 commits into
aws:devfrom
JanHyka:janhyka/testing_phase_1

Conversation

@JanHyka

@JanHyka JanHyka commented May 14, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available:

#286

Description of changes:

Initial step allowing implementation of #286.

This pull request updates the AWS.Messaging library to replace the custom DateTimeHandler abstraction with the .NET 8 TimeProvider for handling time-related functionality. This change modernizes the codebase, improves testability, and removes now-unnecessary code. Several classes and their constructors have been updated to use TimeProvider, and related tests and dependency registrations have also been adjusted.

Key changes include:

Migration to .NET 8 TimeProvider:

  • Replaced all usages of IDateTimeHandler and DateTimeHandler with the built-in TimeProvider throughout the codebase, including in EnvelopeSerializer, SingleTypeSqsPollerEnvelopeSerializer, BackoffHandler, DefaultMessageManager, and InFlightMetadata.

Removal of Obsolete Code:

  • Deleted the now-unnecessary DateTimeHandler and IDateTimeHandler files and interfaces.
  • Constructors of public API classes missing TimeProvider internally use TimeProvider.System and are marked as [Obsolete] - this is to reduce risk of unexpected behavior in case custom TimeProvider is used and propagation chain gets silently broken.

Dependency Injection and Constructor Updates:

  • Updated dependency injection registrations and factory methods to provide TimeProvider.System where required. Added new constructor overloads and marked old ones as obsolete to ease migration.

Test Adjustments and Improvements:

  • Updated unit tests to use the new TimeProvider abstraction, including using FakeTimeProvider for improved testability. Added the Microsoft.Extensions.TimeProvider.Testing NuGet package to test projects.
  • Work around thread safety issue in TestLambdaLogger, allowing significant unit test speedup
  • Unit test accumulative duration drop to ~50% (1.2min -> 38.4s)

Changelog and Documentation:

  • Added a changelog entry indicating the migration from DateTimeHandler to .NET 8 TimeProvider.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

JanHyka added 2 commits May 14, 2026 11:19
~ Replace DateTimeHandler with .NET8 TimeProvider
@JanHyka JanHyka requested review from a team as code owners May 14, 2026 09:52
@JanHyka JanHyka requested review from normj and philasmar May 14, 2026 09:52
@JanHyka JanHyka changed the title Janhyka/testing phase 1 Introduce TimeProvider in place of DateTimeHandler May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant