Use TimeProvider in InMemoryMcpTaskStore for deterministic testing (#1303)

This commit is contained in:
Copilot 2026-02-18 21:47:31 -08:00 • committed by GitHub
commit b967835144
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,7 +35,11 @@ public sealed class InMemoryMcpTaskStore : IMcpTaskStore, IDisposable
private readonly TimeSpan? _defaultTtl;
private readonly TimeSpan? _maxTtl;
private readonly TimeSpan _pollInterval;
#if MCP_TEST_TIME_PROVIDER
private readonly ITimer? _cleanupTimer;
#else
private readonly Timer? _cleanupTimer;
#endif
private readonly int _pageSize;
private readonly int? _maxTasks;
private readonly int? _maxTasksPerSession;
@ -134,7 +138,11 @@ public sealed class InMemoryMcpTaskStore : IMcpTaskStore, IDisposable
cleanupInterval ??= TimeSpan.FromMinutes(1);
if (cleanupInterval.Value != Timeout.InfiniteTimeSpan)
{
#if MCP_TEST_TIME_PROVIDER
_cleanupTimer = _timeProvider.CreateTimer(CleanupExpiredTasks, null, cleanupInterval.Value, cleanupInterval.Value);
#else
_cleanupTimer = new Timer(CleanupExpiredTasks, null, cleanupInterval.Value, cleanupInterval.Value);
#endif
}
}