---
title: "TimeProvider Test Patterns That Hold Up in CI and Production — Daily DevOps & .NET"
url: https://daily.dev/posts/timeprovider-test-patterns-that-hold-up-in-ci-and-production-daily-devops-net-ebwurnbxn
source_url: https://daily-devops.net/posts/timeprovider-test-patterns-that-actually-hold
type: article
source: "Daily DevOps & .NET"
author: "Martin Stühmer"
published: 2026-06-23T16:12:15.463Z
updated: 2026-06-24T13:00:15.489Z
tags: ["testing", ".net", "dependency-injection"]
reading_time: 9
upvotes: 8
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# TimeProvider Test Patterns That Hold Up in CI and Production — Daily DevOps & .NET

**[Daily DevOps & .NET](https://daily.dev/sources/dailydevopsnet)** · [@samtrion](https://daily.dev/samtrion) · 9 min read · 8 upvotes · 0 comments

## Summary

FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing is only the starting point for time-based testing in .NET. The real challenges involve understanding the difference between SetUtcNow (no callbacks) and Advance (fires callbacks), synchronizing async timer callbacks using TaskCompletionSource, correctly ordering awaits before advancing time with PeriodicTimer, using the CancellationTokenSource overload that accepts a TimeProvider to avoid flaky tests, and managing DI lifetime contamination when sharing a WebApplicationFactory across tests. The post also covers BackgroundService integration test patterns and lists scenarios FakeTimeProvider cannot handle, such as DST transitions and Stopwatch precision.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://daily-devops.net/posts/timeprovider-test-patterns-that-actually-hold>

## Similar posts on daily.dev

- [Stop Pretending TimeProvider Doesn't Exist — Daily DevOps & .NET](https://daily.dev/posts/stop-pretending-timeprovider-doesn-t-exist-daily-devops-net-8lez0ga1i) · We Are .NET · 21 upvotes · 1 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#.net](https://daily.dev/tags/.net), [#dependency-injection](https://daily.dev/tags/dependency-injection)

[View this post on daily.dev](https://daily.dev/posts/timeprovider-test-patterns-that-hold-up-in-ci-and-production-daily-devops-net-ebwurnbxn)
