-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathDistributedCacheResumabilityIntegrationTests.cs
More file actions
50 lines (44 loc) · 2.15 KB
/
DistributedCacheResumabilityIntegrationTests.cs
File metadata and controls
50 lines (44 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ModelContextProtocol.Server;
namespace ModelContextProtocol.AspNetCore.Tests;
/// <summary>
/// Integration tests for SSE resumability using <see cref="DistributedCacheEventStreamStore"/>.
/// </summary>
/// <remarks>
/// <para>
/// This class runs the same resumability tests as <see cref="ResumabilityIntegrationTests"/> but
/// using the production <see cref="DistributedCacheEventStreamStore"/> implementation backed by
/// an in-memory distributed cache.
/// </para>
/// <para>
/// These tests verify that the distributed cache implementation correctly stores and retrieves
/// events for resumability, including across simulated disconnections.
/// </para>
/// </remarks>
public class DistributedCacheResumabilityIntegrationTests(ITestOutputHelper testOutputHelper) : ResumabilityIntegrationTestsBase(testOutputHelper)
{
/// <inheritdoc />
protected override ValueTask<ISseEventStreamStore> CreateEventStreamStoreAsync()
{
// Create a new in-memory distributed cache for each test
var cache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
// Configure the store with shorter expiration times suitable for testing
var options = new DistributedCacheEventStreamStoreOptions
{
// Use the in-memory distributed cache
Cache = cache,
// Use shorter polling interval for faster test execution
StreamReaderPollingInterval = TimeSpan.FromMilliseconds(50),
// Use shorter expiration times for tests
EventSlidingExpiration = TimeSpan.FromMinutes(5),
EventAbsoluteExpiration = TimeSpan.FromMinutes(10),
MetadataSlidingExpiration = TimeSpan.FromMinutes(5),
MetadataAbsoluteExpiration = TimeSpan.FromMinutes(10),
};
var store = new DistributedCacheEventStreamStore(Options.Create(options), LoggerFactory.CreateLogger<DistributedCacheEventStreamStore>());
return new ValueTask<ISseEventStreamStore>(store);
}
}