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
@@ -142,6 +142,77 @@ public sealed class RendezvousClientIntegrationTests
}
}
[Fact]
public async Task BrowserStreamResetsInvalidCursorReplaysReconnectAndReleasesConnections()
{
await using ClientTestHost host = await ClientTestHost.StartAsync();
RendezvousPublisherClient publisher = new(host.HttpClient);
RendezvousSessionBrowserClient browser = new(host.HttpClient);
PublishedSession session = AssertSuccess(await publisher.RegisterAsync(
CreateRegistration(200),
host.PublisherCredential));
BindPresence(host, session, 41_200);
BrowseSessionsRequest request = BrowseRequest();
BrowseSessionsResponse snapshot = AssertSuccess(await browser.BrowseAsync(request));
Assert.False(string.IsNullOrWhiteSpace(snapshot.StreamCursor));
using CancellationTokenSource timeout = new(TimeSpan.FromSeconds(10));
await using (IAsyncEnumerator<RendezvousClientResult<SessionStreamEvent>> invalid = browser
.StreamAsync(request, CorruptCursor(snapshot.StreamCursor), timeout.Token)
.GetAsyncEnumerator(timeout.Token))
{
Assert.True(await invalid.MoveNextAsync());
Assert.Equal(SessionStreamEventKind.Reset, AssertSuccess(invalid.Current).Kind);
Assert.False(await invalid.MoveNextAsync());
}
await using IAsyncEnumerator<RendezvousClientResult<SessionStreamEvent>> events = browser
.StreamAsync(request, snapshot.StreamCursor, timeout.Token)
.GetAsyncEnumerator(timeout.Token);
Task<bool> upsertPending = events.MoveNextAsync().AsTask();
Assert.True((await publisher.UpdateAsync(
session,
new UpdateSessionRequest
{
BuildVersion = "2.0.0",
DisplayName = "Live update",
Capacity = new() { CurrentPlayers = 3, MaximumPlayers = 8 },
Metadata = new() { ["mode"] = "online-coop" },
},
host.PublisherCredential,
timeout.Token)).IsSuccess);
Assert.True(await upsertPending);
SessionStreamEvent upsert = AssertSuccess(events.Current);
Assert.Equal(SessionStreamEventKind.SessionUpsert, upsert.Kind);
Assert.Equal("Live update", upsert.Session!.DisplayName);
await using (IAsyncEnumerator<RendezvousClientResult<SessionStreamEvent>> replay = browser
.StreamAsync(request, snapshot.StreamCursor, timeout.Token)
.GetAsyncEnumerator(timeout.Token))
{
Assert.True(await replay.MoveNextAsync());
SessionStreamEvent replayed = AssertSuccess(replay.Current);
Assert.Equal(SessionStreamEventKind.SessionUpsert, replayed.Kind);
Assert.Equal(upsert.Cursor, replayed.Cursor);
Assert.Equal("Live update", replayed.Session!.DisplayName);
}
Task<bool> removePending = events.MoveNextAsync().AsTask();
Assert.True((await publisher.DeregisterAsync(
session,
host.PublisherCredential,
timeout.Token)).IsSuccess);
Assert.True(await removePending);
SessionStreamEvent remove = AssertSuccess(events.Current);
Assert.Equal(SessionStreamEventKind.SessionRemove, remove.Kind);
Assert.Equal(session.ListingId, remove.ListingId);
}
private static string CorruptCursor(string cursor)
{
char replacement = cursor[^1] == 'a' ? 'b' : 'a';
return cursor[..^1] + replacement;
}
private static T AssertSuccess<T>(RendezvousClientResult<T> result)
{
Assert.True(result.IsSuccess, result.Message);
@@ -210,7 +281,8 @@ public sealed class RendezvousClientIntegrationTests
{
ManualRendezvousClock clock = new(ProvisioningTestData.Now);
EphemeralStoreOptions stateOptions = new();
InMemoryEphemeralRendezvousStore store = new(stateOptions, clock, clock);
SessionChangeJournal changes = new(new SessionChangeJournalOptions());
InMemoryEphemeralRendezvousStore store = new(stateOptions, clock, clock, changes);
EphemeralCapabilityIssuer capabilities = new();
ProvisioningRuntime provisioning = ProvisioningRuntime.Create(
ProvisioningTestData.CreateOptions(),
@@ -239,7 +311,10 @@ public sealed class RendezvousClientIntegrationTests
builder.Services.AddSingleton(SessionLeaseTiming.From(stateOptions));
builder.Services.AddSingleton<SessionLeaseService>();
builder.Services.AddSingleton<SessionBrowserCursorCodec>();
builder.Services.AddSingleton<SessionStreamCursorCodec>();
builder.Services.AddSingleton(changes);
builder.Services.AddSingleton<SessionBrowserService>();
builder.Services.AddSingleton<SessionStreamService>();
WebApplication app = builder.Build();
app.UseExceptionHandler();