feat(browser): stream bounded live session updates (#26)
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user