test: add bounded SDK2 close ownership controls

This commit is contained in:
Joseph Doherty
2026-11-10 16:26:26 -05:00
parent ed60970fc2
commit 235196beb2
4 changed files with 314 additions and 1 deletions
@@ -122,12 +122,15 @@ public sealed class EventHistoryPagingOverTheWireTests
/// <summary>(time, id) order, [start, end), cap + truncation flag — the SQL backends' contract.</summary>
internal sealed class SqlLikeEventSource(List<HistoricalEvent> events) : IHistorianDataSource
{
private int _reads;
internal int ReadCount => Volatile.Read(ref _reads);
private readonly List<HistoricalEvent> _all =
events.OrderBy(e => e.EventTimeUtc).ThenBy(e => e.EventId, StringComparer.Ordinal).ToList();
public async Task<HistoricalEventsResult> ReadEventsAsync(
string? sourceName, DateTime startUtc, DateTime endUtc, int maxEvents, CancellationToken ct)
{
Interlocked.Increment(ref _reads);
await Task.Delay(1, ct).ConfigureAwait(false); // complete on a pool thread, like a real backend
var window = _all.Where(e => e.EventTimeUtc >= startUtc && e.EventTimeUtc < endUtc).ToList();
var cap = maxEvents <= 0 ? 1000 : maxEvents;