feat(browser): stream bounded live session updates (#26)
quality-gate / quality (push) Failing after 1m47s
quality-gate / container (push) Has been skipped

This commit is contained in:
KyuubiYoru
2026-07-16 23:25:48 +02:00
parent 95c3a4aed6
commit 06c4ecf8f3
34 changed files with 2249 additions and 27 deletions
@@ -167,6 +167,88 @@ public sealed class RendezvousClientBehaviorTests
Assert.Contains("gameId=space-game", handler.RequestUris[0].Query, StringComparison.Ordinal);
}
[Fact]
public async Task StreamRejectsMalformedAndOversizedEventEnvelopes()
{
string[] bodies =
[
"event: session_upsert\nid: valid-cursor\ndata: {}\n\n",
"data: " + new string('x', ContractLimits.SessionStreamEventMaxBytes + 1) + "\n\n",
];
foreach (string body in bodies)
{
StringContent content = new(body, Encoding.UTF8, "text/event-stream");
ScriptedHandler handler = new(Response(HttpStatusCode.OK, content));
using HttpClient httpClient = new(handler)
{
BaseAddress = new("http://rendezvous.test/"),
};
RendezvousSessionBrowserClient browser = new(httpClient);
await using IAsyncEnumerator<RendezvousClientResult<SessionStreamEvent>> events = browser
.StreamAsync(new BrowseSessionsRequest
{
GameId = new("space-game"),
EnvironmentId = new("production"),
ProtocolVersion = 7,
}, "valid-stream-cursor")
.GetAsyncEnumerator();
Assert.True(await events.MoveNextAsync());
Assert.False(events.Current.IsSuccess);
Assert.Equal(RendezvousErrorCode.InternalError, events.Current.Error);
}
}
[Fact]
public async Task StreamRequiresANonEmptySnapshotCursor()
{
using HttpClient httpClient = new(new ScriptedHandler())
{
BaseAddress = new("http://rendezvous.test/"),
};
RendezvousSessionBrowserClient browser = new(httpClient);
await Assert.ThrowsAsync<ArgumentException>(async () =>
{
await foreach (RendezvousClientResult<SessionStreamEvent> _ in browser.StreamAsync(
new BrowseSessionsRequest
{
GameId = new("space-game"),
EnvironmentId = new("production"),
ProtocolVersion = 7,
},
string.Empty))
{
}
});
}
[Fact]
public async Task StreamOpeningIsBoundedByTheConfiguredRequestTimeout()
{
using HttpClient httpClient = new(new SilentHandler())
{
BaseAddress = new("http://rendezvous.test/"),
};
RendezvousSessionBrowserClient browser = new(
httpClient,
new RendezvousClientOptions
{
MaximumSafeRetries = 0,
RequestTimeout = TimeSpan.FromMilliseconds(20),
});
await using IAsyncEnumerator<RendezvousClientResult<SessionStreamEvent>> events = browser
.StreamAsync(new BrowseSessionsRequest
{
GameId = new("space-game"),
EnvironmentId = new("production"),
ProtocolVersion = 7,
}, "valid-stream-cursor")
.GetAsyncEnumerator();
Assert.True(await events.MoveNextAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(2)));
Assert.Equal(RendezvousErrorCode.ServiceUnavailable, events.Current.Error);
}
[Fact]
public async Task LeaseMaintainerReportsLeaseLoss()
{