Skip to content

Commit d63c65d

Browse files
authored
[QUIC] Improve idle timeout tests (#73228)
* Improve idle timeout tests * Minor change * Code review feedback
1 parent 02c0b97 commit d63c65d

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

Diff for: src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicTests.cs

+38-19
Original file line numberDiff line numberDiff line change
@@ -698,25 +698,6 @@ ValueTask<QuicStream> OpenStreamAsync(QuicConnection connection, CancellationTok
698698
await serverConnection.DisposeAsync();
699699
}
700700

701-
702-
[Fact]
703-
[OuterLoop("May take several seconds")]
704-
public async Task SetListenerTimeoutWorksWithSmallTimeout()
705-
{
706-
var listenerOptions = new QuicListenerOptions()
707-
{
708-
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
709-
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
710-
ConnectionOptionsCallback = (_, _, _) => ValueTask.FromResult(CreateQuicServerOptions())
711-
};
712-
713-
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(null, listenerOptions);
714-
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverConnection.AcceptInboundStreamAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(100)));
715-
716-
await serverConnection.DisposeAsync();
717-
await clientConnection.DisposeAsync();
718-
}
719-
720701
[Theory]
721702
[MemberData(nameof(WriteData))]
722703
public async Task WriteTests(int[][] writes)
@@ -1179,5 +1160,43 @@ public async Task IncompatibleAlpn_ThrowsAuthenticationException()
11791160

11801161
await Assert.ThrowsAsync<AuthenticationException>(async () => await CreateQuicConnection(clientOptions)).WaitAsync(TimeSpan.FromSeconds(30));
11811162
}
1163+
1164+
[Fact]
1165+
[OuterLoop("May take several seconds")]
1166+
public async Task IdleTimeout_ThrowsQuicException()
1167+
{
1168+
QuicListenerOptions listenerOptions = new QuicListenerOptions()
1169+
{
1170+
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0),
1171+
ApplicationProtocols = new List<SslApplicationProtocol>() { ApplicationProtocol },
1172+
ConnectionOptionsCallback = (_, _, _) =>
1173+
{
1174+
var serverOptions = CreateQuicServerOptions();
1175+
serverOptions.MaxInboundBidirectionalStreams = 1;
1176+
serverOptions.MaxInboundUnidirectionalStreams = 1;
1177+
serverOptions.IdleTimeout = TimeSpan.FromSeconds(1);
1178+
return ValueTask.FromResult(serverOptions);
1179+
}
1180+
};
1181+
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(null, listenerOptions);
1182+
1183+
await using (clientConnection)
1184+
await using (serverConnection)
1185+
{
1186+
using QuicStream clientStream = await clientConnection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional);
1187+
await clientStream.WriteAsync(new byte[1]);
1188+
using QuicStream serverStream = await serverConnection.AcceptInboundStreamAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(10));
1189+
await serverStream.ReadAsync(new byte[1]);
1190+
1191+
ValueTask<QuicStream> acceptTask = serverConnection.AcceptInboundStreamAsync();
1192+
1193+
// read attempts should block until idle timeout
1194+
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverStream.ReadAsync(new byte[10])).WaitAsync(TimeSpan.FromSeconds(10));
1195+
1196+
// write and accept should throw as well
1197+
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await serverStream.WriteAsync(new byte[10])).WaitAsync(TimeSpan.FromSeconds(10));
1198+
await AssertThrowsQuicExceptionAsync(QuicError.ConnectionIdle, async () => await acceptTask).WaitAsync(TimeSpan.FromSeconds(10));
1199+
}
1200+
}
11821201
}
11831202
}

0 commit comments

Comments
 (0)