public async Task SendMoreThanStreamLimitRequests_Succeeds(int streamLimit)
        {
            using Http3LoopbackServer server = CreateHttp3LoopbackServer();

            Task serverTask = Task.Run(async() =>
            {
                using Http3LoopbackConnection connection = (Http3LoopbackConnection) await server.EstablishGenericConnectionAsync();
                for (int i = 0; i < streamLimit + 1; ++i)
                {
                    using Http3LoopbackStream stream = await connection.AcceptRequestStreamAsync();
                    await stream.HandleRequestAsync();
                }
            });

            Task clientTask = Task.Run(async() =>
            {
                using HttpClient client = CreateHttpClient();

                for (int i = 0; i < streamLimit + 1; ++i)
                {
                    using HttpRequestMessage request = new()
                          {
                              Method        = HttpMethod.Get,
                              RequestUri    = server.Address,
                              Version       = HttpVersion30,
                              VersionPolicy = HttpVersionPolicy.RequestVersionExact
                          };
                    using var response = await client.SendAsync(request).WaitAsync(TimeSpan.FromSeconds(10));
                }
            });

            await new[] { clientTask, serverTask }.WhenAllOrAnyFailed(20_000);
        }
        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);
        }
示例#3
0
        public async Task SendMoreThanStreamLimitRequests_Succeeds(int streamLimit)
        {
            // [ActiveIssue("https://github.com/dotnet/runtime/issues/55957")]
            if (this.UseQuicImplementationProvider == QuicImplementationProviders.Mock)
            {
                return;
            }

            using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options()
            {
                MaxBidirectionalStreams = streamLimit
            });

            Task serverTask = Task.Run(async() =>
            {
                using Http3LoopbackConnection connection = (Http3LoopbackConnection) await server.EstablishGenericConnectionAsync();
                for (int i = 0; i < streamLimit + 1; ++i)
                {
                    using Http3LoopbackStream stream = await connection.AcceptRequestStreamAsync();
                    await stream.HandleRequestAsync();
                }
            });

            Task clientTask = Task.Run(async() =>
            {
                using HttpClient client = CreateHttpClient();

                for (int i = 0; i < streamLimit + 1; ++i)
                {
                    HttpRequestMessage request = new()
                    {
                        Method        = HttpMethod.Get,
                        RequestUri    = server.Address,
                        Version       = HttpVersion30,
                        VersionPolicy = HttpVersionPolicy.RequestVersionExact
                    };
                    using var response = await client.SendAsync(request).WaitAsync(TimeSpan.FromSeconds(10));
                }
            });

            await new[] { clientTask, serverTask }.WhenAllOrAnyFailed(20_000);
        }
        public async Task SendStreamLimitRequestsConcurrently_Succeeds(int streamLimit)
        {
            using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options()
            {
                MaxBidirectionalStreams = streamLimit
            });

            Task serverTask = Task.Run(async() =>
            {
                using Http3LoopbackConnection connection = (Http3LoopbackConnection) await server.EstablishGenericConnectionAsync();
                for (int i = 0; i < streamLimit; ++i)
                {
                    using Http3LoopbackStream stream = await connection.AcceptRequestStreamAsync();
                    await stream.HandleRequestAsync();
                }
            });

            Task clientTask = Task.Run(async() =>
            {
                using HttpClient client = CreateHttpClient();

                var tasks = new Task <HttpResponseMessage> [streamLimit];
                Parallel.For(0, streamLimit, i =>
                {
                    HttpRequestMessage request = new()
                    {
                        Method        = HttpMethod.Get,
                        RequestUri    = server.Address,
                        Version       = HttpVersion30,
                        VersionPolicy = HttpVersionPolicy.RequestVersionExact
                    };

                    tasks[i] = client.SendAsync(request);
                });

                var responses = await Task.WhenAll(tasks);
                foreach (var response in responses)
                {
                    response.Dispose();
                }
            });