Fix session timeout due to timestamp frequency mismatch and activity tracking (#1106)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
This commit is contained in:
parent
1b846cb76c
commit
aaffd71c69
1 changed files with 39 additions and 1 deletions
|
|
@ -521,6 +521,33 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
|
|||
Assert.StartsWith("MaxIdleSessionCount of 2 exceeded. Closing idle session", idleLimitLogMessage.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ActiveSession_WithPeriodicRequests_DoesNotTimeout()
|
||||
{
|
||||
var fakeTimeProvider = new FakeTimeProvider();
|
||||
Builder.Services.AddMcpServer().WithHttpTransport(options =>
|
||||
{
|
||||
options.IdleTimeout = TimeSpan.FromHours(2);
|
||||
options.TimeProvider = fakeTimeProvider;
|
||||
});
|
||||
|
||||
await StartAsync();
|
||||
await CallInitializeAndValidateAsync();
|
||||
|
||||
// Simulate multiple POST requests over a period longer than IdleTimeout
|
||||
// Each request should update LastActivityTicks, preventing timeout
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// Advance time by 1 hour between requests
|
||||
fakeTimeProvider.Advance(TimeSpan.FromHours(1));
|
||||
await CallEchoAndValidateAsync();
|
||||
}
|
||||
|
||||
// Total time elapsed: 5 hours (> 2 hour IdleTimeout)
|
||||
// But session should still be alive because of periodic activity
|
||||
await CallEchoAndValidateAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task McpServer_UsedOutOfScope_CanSendNotifications()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue