Skip to content
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

[QUIC] Improve idle timeout tests #73228

Merged
merged 4 commits into from
Aug 8, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,25 +611,6 @@ ValueTask<QuicStream> OpenStreamAsync(QuicConnection connection, CancellationTok
await serverConnection.DisposeAsync();
}


[Fact]
[OuterLoop("May take several seconds")]
public async Task SetListenerTimeoutWorksWithSmallTimeout()
{
var listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
ConnectionOptionsCallback = (_, _, _) => ValueTask.FromResult(CreateQuicServerOptions())
};

(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(null, listenerOptions);
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverConnection.AcceptInboundStreamAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(100)));

await serverConnection.DisposeAsync();
await clientConnection.DisposeAsync();
}

[Theory]
[MemberData(nameof(WriteData))]
public async Task WriteTests(int[][] writes)
Expand Down Expand Up @@ -1082,5 +1063,43 @@ await RunBidirectionalClientServer(
Assert.True(serverStream.ReadsClosed.IsCompletedSuccessfully);
});
}

[Fact]
[OuterLoop("May take several seconds")]
public async Task IdleTimeout_ThrowsQuicException()
{
QuicListenerOptions listenerOptions = new QuicListenerOptions()
{
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
ConnectionOptionsCallback = (_, _, _) =>
{
var serverOptions = CreateQuicServerOptions();
serverOptions.MaxInboundBidirectionalStreams = 1;
serverOptions.MaxInboundUnidirectionalStreams = 1;
serverOptions.IdleTimeout = TimeSpan.FromSeconds(1);
return ValueTask.FromResult(serverOptions);
}
};
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(null, listenerOptions);

await using (clientConnection)
await using (serverConnection)
{
using QuicStream clientStream = await clientConnection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional);
await clientStream.WriteAsync(new byte[1]);
using QuicStream serverStream = await serverConnection.AcceptInboundStreamAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(10));
await serverStream.ReadAsync(new byte[1]);

ValueTask<QuicStream> acceptTask = serverConnection.AcceptInboundStreamAsync();

// read attempts should block until idle timeout
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverStream.ReadAsync(new byte[10])).WaitAsync(TimeSpan.FromSeconds(10));

// write and accept should throw as well
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverStream.WriteAsync(new byte[10])).WaitAsync(TimeSpan.FromSeconds(10));
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await acceptTask).WaitAsync(TimeSpan.FromSeconds(10));
}
}
}
}