Skip to content

Use TimeProvider in InMemoryMcpTaskStore for deterministic testing#1303

Merged
halter73 merged 3 commits intomainfrom
copilot/update-inmemory-tasks-store
Feb 19, 2026
Merged

Use TimeProvider in InMemoryMcpTaskStore for deterministic testing#1303
halter73 merged 3 commits intomainfrom
copilot/update-inmemory-tasks-store

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Plan: Add TimeProvider Support to InMemoryMcpTaskStore ✅

  • Update InMemoryMcpTaskStore to use TimeProvider instead of System.Threading.Timer
    • Replace Timer? with ITimer? field (conditionally compiled)
    • Update constructor to accept optional TimeProvider parameter (test-only)
    • Use timeProvider.CreateTimer() instead of new Timer()
  • Update tests to use FakeTimeProvider and remove Task.Delay calls
    • Update CleanupExpiredTasks_RemovesExpiredTasks to use FakeTimeProvider
    • Update Dispose_StopsCleanupTimer to use FakeTimeProvider
    • Update UpdateTaskStatusAsync_UpdatesLastUpdatedAt to use FakeTimeProvider
    • Update CreateTaskAsync_MaxTasksPerSession_ExcludesExpiredTasks to use FakeTimeProvider
    • Update ListTasksAsync_ConsistentWithExpiredTasksRemovedBetweenPages to use FakeTimeProvider
  • Run full test suite to ensure no regressions (All 1562 tests passed)
  • Run security scanning (No alerts found)
  • Fix net472 compatibility issue: Replace cleanupInterval * 3 with TimeSpan.FromTicks(cleanupInterval.Ticks * 3)

Summary

Successfully updated InMemoryMcpTaskStore to use TimeProvider for deterministic, fast testing. All tests that previously used Task.Delay now use FakeTimeProvider.Advance() to simulate time passage, making them:

  • Deterministic: No more timing-related flakiness
  • Fast: Tests complete instantly instead of waiting for real time delays
  • Maintainable: Clear intent through explicit time advancement
  • Compatible: Works with all target frameworks including net472

The changes are backward compatible with production code (using conditional compilation) and all tests pass successfully.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Copilot AI changed the title [WIP] Update InMemoryMcpTaskStore to use TimeProvider Use TimeProvider in InMemoryMcpTaskStore for deterministic testing Feb 18, 2026
Copilot AI requested a review from halter73 February 18, 2026 02:44
stephentoub
stephentoub previously approved these changes Feb 18, 2026
@stephentoub stephentoub marked this pull request as ready for review February 18, 2026 18:57
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
@halter73 halter73 enabled auto-merge (squash) February 19, 2026 02:56
@halter73 halter73 merged commit b967835 into main Feb 19, 2026
16 of 17 checks passed
@halter73 halter73 deleted the copilot/update-inmemory-tasks-store branch February 19, 2026 05:47
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.

4 participants