Resolve all high-severity architecture review findings
This commit is contained in:
@@ -44,6 +44,34 @@ public class SiteStreamPullAuditEventsTests : TestKit
|
||||
?? DateTime.SpecifyKind(new DateTime(2026, 5, 20, 10, 0, 0), DateTimeKind.Utc),
|
||||
sourceSiteId: "site-1");
|
||||
|
||||
[Fact]
|
||||
public async Task LargeAuditRows_ArePagedByWireBytes_AndCursorMakesProgress()
|
||||
{
|
||||
var rows = Enumerable.Range(0, 256).Select(i => ScadaBridgeAuditEventFactory.Create(
|
||||
channel: AuditChannel.ApiOutbound, kind: AuditKind.ApiCall, status: AuditStatus.Failed,
|
||||
occurredAtUtc: DateTime.UtcNow.AddSeconds(i), sourceSiteId: "site-1",
|
||||
errorDetail: new string('界', 64 * 1024 / 3), errorMessage: new string('x', 2048))).ToList();
|
||||
var queue = Substitute.For<ISiteAuditQueue>();
|
||||
queue.ReadPendingSinceAsync(Arg.Any<DateTime>(), Arg.Any<int>(), Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(c => (IReadOnlyList<AuditEvent>)rows.Skip(c.ArgAt<string?>(2) is { } id
|
||||
? rows.FindIndex(e => e.EventId.ToString() == id) + 1 : 0).Take(c.ArgAt<int>(1)).ToList());
|
||||
var server = CreateServer();
|
||||
server.SetSiteAuditQueue(queue);
|
||||
var request = new PullAuditEventsRequest { BatchSize = 256 };
|
||||
var seen = new HashSet<string>();
|
||||
while (true)
|
||||
{
|
||||
var response = await server.PullAuditEvents(request, NewContext());
|
||||
Assert.True(response.CalculateSize() + 5 <= 2 * 1024 * 1024);
|
||||
foreach (var row in response.Events) Assert.True(seen.Add(row.EventId));
|
||||
if (!response.MoreAvailable) break;
|
||||
Assert.NotEmpty(response.Events);
|
||||
request.AfterId = response.Events[^1].EventId;
|
||||
request.SinceUtc = response.Events[^1].OccurredAtUtc;
|
||||
}
|
||||
Assert.Equal(256, seen.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PullAuditEvents_NoQueueWired_ReturnsEmptyResponse()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user