Skip to content

Commit

Permalink
[QUIC] Improve idle timeout tests (#73228)
Browse files Browse the repository at this point in the history
* Improve idle timeout tests

* Minor change

* Code review feedback
  • Loading branch information
rzikm authored Aug 8, 2022
1 parent 02c0b97 commit d63c65d
Showing 1 changed file with 38 additions and 19 deletions.
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 @@ -698,25 +698,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 @@ -1179,5 +1160,43 @@ public async Task IncompatibleAlpn_ThrowsAuthenticationException()

await Assert.ThrowsAsync<AuthenticationException>(async () => await CreateQuicConnection(clientOptions)).WaitAsync(TimeSpan.FromSeconds(30));
}

[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));
}
}
}
}

0 comments on commit d63c65d

Please sign in to comment.