public async Task Read_ConnectionAborted_Throws() { const int ExpectedErrorCode = 1234; await Task.Run(async() => { using QuicListener listener = CreateQuicListener(); ValueTask <QuicConnection> serverConnectionTask = listener.AcceptConnectionAsync(); using QuicConnection clientConnection = CreateQuicConnection(listener.ListenEndPoint); await clientConnection.ConnectAsync(); using QuicConnection serverConnection = await serverConnectionTask; await using QuicStream clientStream = clientConnection.OpenBidirectionalStream(); await clientStream.WriteAsync(new byte[1]); await using QuicStream serverStream = await serverConnection.AcceptStreamAsync(); await serverStream.ReadAsync(new byte[1]); await clientConnection.CloseAsync(ExpectedErrorCode); byte[] buffer = new byte[100]; QuicConnectionAbortedException ex = await Assert.ThrowsAsync <QuicConnectionAbortedException>(() => serverStream.ReadAsync(buffer).AsTask()); Assert.Equal(ExpectedErrorCode, ex.ErrorCode); }).TimeoutAfter(millisecondsTimeout: 5_000); }
public async Task AcceptStream_ConnectionAborted_ByClient_Throws() { using var sync = new SemaphoreSlim(0); await RunClientServer( async clientConnection => { await clientConnection.CloseAsync(ExpectedErrorCode); sync.Release(); }, async serverConnection => { await sync.WaitAsync(); QuicConnectionAbortedException ex = await Assert.ThrowsAsync <QuicConnectionAbortedException>(() => serverConnection.AcceptStreamAsync().AsTask()); Assert.Equal(ExpectedErrorCode, ex.ErrorCode); }); }
public async Task ReservedFrameType_Throws() { const int ReservedHttp2PriorityFrameId = 0x2; const long UnexpectedFrameErrorCode = 0x105; using Http3LoopbackServer server = CreateHttp3LoopbackServer(); Task serverTask = Task.Run(async() => { using Http3LoopbackConnection connection = (Http3LoopbackConnection) await server.EstablishGenericConnectionAsync(); using Http3LoopbackStream stream = await connection.AcceptRequestStreamAsync(); await stream.SendFrameAsync(ReservedHttp2PriorityFrameId, new byte[8]); QuicConnectionAbortedException ex = await Assert.ThrowsAsync <QuicConnectionAbortedException>(async() => { await stream.HandleRequestAsync(); using Http3LoopbackStream stream2 = await connection.AcceptRequestStreamAsync(); }); Assert.Equal(UnexpectedFrameErrorCode, ex.ErrorCode); }); Task clientTask = Task.Run(async() => { using HttpClient client = CreateHttpClient(); using HttpRequestMessage request = new() { Method = HttpMethod.Get, RequestUri = server.Address, Version = HttpVersion30, VersionPolicy = HttpVersionPolicy.RequestVersionExact }; await Assert.ThrowsAsync <HttpRequestException>(async() => await client.SendAsync(request)); }); await new[] { clientTask, serverTask }.WhenAllOrAnyFailed(20_000); }