Skip to content

Use TimeProvider in InMemoryMcpTaskStore for deterministic testing#1303

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/update-inmemory-tasks-store
Draft

Use TimeProvider in InMemoryMcpTaskStore for deterministic testing#1303
Copilot wants to merge 2 commits intomainfrom
copilot/update-inmemory-tasks-store

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Fixes flaky CleanupExpiredTasks_RemovesExpiredTasks test caused by timer-based cleanup relying on real time delays.

Changes

  • InMemoryMcpTaskStore: Conditionally use ITimer (via TimeProvider.CreateTimer()) when MCP_TEST_TIME_PROVIDER is defined, falling back to Timer for production builds
  • Tests: Replace Task.Delay() with FakeTimeProvider.Advance() in 5 time-dependent tests:
    • CleanupExpiredTasks_RemovesExpiredTasks
    • Dispose_StopsCleanupTimer
    • UpdateTaskStatusAsync_UpdatesLastUpdatedAt
    • CreateTaskAsync_MaxTasksPerSession_ExcludesExpiredTasks
    • ListTasksAsync_ConsistentWithExpiredTasksRemovedBetweenPages

Example

Before:

await Task.Delay(250, cancellationToken);  // Wait for TTL expiration and cleanup

After:

fakeTime.Advance(ttl + TimeSpan.FromMilliseconds(1));  // Expire task
fakeTime.Advance(cleanupInterval);  // Trigger cleanup timer

Tests are now deterministic and run >2 seconds faster.


💡 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
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.

2 participants