-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new KeepAliveInterval option in QuicClientTransportOptions #3991
Changes from 3 commits
c093fe8
81295fb
1c545cc
b6e769e
dc5b808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ public async Task Compress_request_payload( | |
new BrotliStream(outStream, CompressionMode.Decompress) : | ||
new DeflateStream(outStream, CompressionMode.Decompress); | ||
var decompressedPayload = new byte[4096]; | ||
await decompressedStream.ReadAsync(decompressedPayload); | ||
await decompressedStream.ReadAtLeastAsync(decompressedPayload, _payload.Length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are tiny unrelated fixes for analyzer warnings introduced in .NET 9.0. |
||
Assert.That(decompressedPayload, Is.EqualTo(_payload)); | ||
payloadWriter.Complete(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ public void FixtureSetUp() | |
/// timeout.</summary> | ||
/// <remarks>The behavior shown by this test is not desirable for IceRPC: we would prefer QUIC or IceRPC's QUIC | ||
/// wrapper to keep this connection alive when there is an outstanding request. | ||
/// See https://github.com/icerpc/icerpc-csharp/issues/3353.</remarks> | ||
/// See <see href="https://github.com/icerpc/icerpc-csharp/issues/3353" />.</remarks> | ||
[Test] | ||
public async Task Quic_connection_idle_after_idle_timeout([Values]bool configureServer) | ||
{ | ||
|
@@ -60,14 +60,56 @@ public async Task Quic_connection_idle_after_idle_timeout([Values]bool configure | |
// Act / Assert | ||
var startTime = TimeSpan.FromMilliseconds(Environment.TickCount64); | ||
|
||
Assert.That(readResult.Buffer.ToArray(), Is.EqualTo(data)); | ||
|
||
Assert.That( | ||
async () => await sut.Local.Input.ReadAsync().AsTask(), | ||
Throws.InstanceOf<IceRpcException>().With.Property("IceRpcError").EqualTo(IceRpcError.ConnectionIdle)); | ||
|
||
Assert.That( | ||
TimeSpan.FromMilliseconds(Environment.TickCount64) - startTime, | ||
Is.GreaterThan(TimeSpan.FromMilliseconds(490))); | ||
|
||
Assert.That(readResult.Buffer.ToArray(), Is.EqualTo(data)); | ||
} | ||
|
||
/// <summary>Verifies the QUIC connection is kept alive by the keep alive interval.</summary> | ||
[Test] | ||
public async Task Quic_connection_kept_alive_by_keep_alive_interval() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection().AddQuicTest(); | ||
|
||
services.AddOptions<QuicServerTransportOptions>("server").Configure( | ||
options => options.IdleTimeout = TimeSpan.FromMilliseconds(500)); | ||
|
||
services.AddOptions<QuicClientTransportOptions>("client").Configure( | ||
options => options.KeepAliveInterval = TimeSpan.FromMilliseconds(250)); | ||
|
||
await using ServiceProvider provider = services.BuildServiceProvider(validateScopes: true); | ||
|
||
var clientServerConnection = provider.GetRequiredService<ClientServerMultiplexedConnection>(); | ||
await clientServerConnection.AcceptAndConnectAsync(); | ||
using var sut = await clientServerConnection.CreateAndAcceptStreamAsync(bidirectional: true); | ||
|
||
// Simulate a request | ||
var data = new byte[] { 0x1, 0x2, 0x3 }; | ||
await sut.Local.Output.WriteAsync(data); | ||
ReadResult readResult = await sut.Remote.Input.ReadAsync(); | ||
|
||
// Act/Assert | ||
|
||
// Without the keep-alive interval, the idle timer aborts the connection after 500ms. | ||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think would be clear to write the response and close the stream after the delay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I reworked the test and removed the cancellation token source. Note that with QUIC, canceling a read is fatal to the stream. You can't cancel reading and then start reading again. We may be doing the same in Slic. |
||
|
||
#if NET9_0_OR_GREATER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes the unit tests are built with the same version of .NET as the IceRpc.Transport.Quic assembly (a safe assumption). |
||
Assert.That( | ||
async () => await sut.Local.Input.ReadAsync(cts.Token), | ||
Throws.InstanceOf<OperationCanceledException>()); | ||
#else | ||
Assert.That( | ||
async () => await sut.Local.Input.ReadAsync().AsTask(), | ||
Throws.InstanceOf<IceRpcException>().With.Property("IceRpcError").EqualTo(IceRpcError.ConnectionIdle)); | ||
#endif | ||
|
||
Assert.That(readResult.Buffer.ToArray(), Is.EqualTo(data)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the default from Zero to 30 seconds - which is the msquic default (= what Zero meant). It's clearer to spell out the actual default, and it's highly desirable to use the same default in all IceRPC implementation.