Request-in-flight GOAWAY test (dotnet/corefx#39501)
authorKrzysztof Wicher <mordotymoja@gmail.com>
Tue, 16 Jul 2019 00:00:19 +0000 (17:00 -0700)
committerGitHub <noreply@github.com>
Tue, 16 Jul 2019 00:00:19 +0000 (17:00 -0700)
* request-in-flight GOAWAY test

* apply feedback

Commit migrated from https://github.com/dotnet/corefx/commit/3eabd4c7f1cc439233e0f8bae3ba37a8d73b7e8d

src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs

index 77169cf..37f0841 100644 (file)
@@ -779,6 +779,51 @@ namespace System.Net.Http.Functional.Tests
         }
 
         [ConditionalFact(nameof(SupportsAlpn))]
+        public async Task GoAwayFrame_RequestInFlight_Finished()
+        {
+            await Http2LoopbackServer.CreateClientAndServerAsync(async uri =>
+                {
+                    using (HttpClient client = CreateHttpClient())
+                    {
+                        HttpResponseMessage response = await client.GetAsync(uri);
+                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+                        byte[] responseBody = await response.Content.ReadAsByteArrayAsync();
+
+                        Assert.Equal(
+                            new byte[20]
+                            {
+                                5, 4, 3, 2, 1,
+                                11, 10, 9, 8, 7, 6,
+                                15, 14, 13, 12,
+                                20, 19, 18, 17, 16,
+                            },
+                            responseBody);
+                    }
+                },
+                async server =>
+                {
+                    Http2LoopbackConnection connection = await server.EstablishConnectionAsync();
+                    int streamId = await connection.ReadRequestHeaderAsync();
+
+                    await connection.SendDefaultResponseHeadersAsync(streamId);
+
+                    await connection.SendResponseBodyAsync(streamId, new byte[5] { 5, 4, 3, 2, 1 }, isFinal: false);
+                    await connection.SendResponseBodyAsync(streamId, new byte[6] { 11, 10, 9, 8, 7, 6 }, isFinal: false);
+
+                    // Signal that our request is the last thing which will be processed
+                    await connection.SendGoAway(streamId);
+
+                    // Make sure client received GOAWAY
+                    await connection.PingPong();
+
+                    await connection.SendResponseBodyAsync(streamId, new byte[4] { 15, 14, 13, 12 }, isFinal: false);
+                    await connection.SendResponseBodyAsync(streamId, new byte[5] { 20, 19, 18, 17, 16 }, isFinal: true);
+
+                    await connection.WaitForConnectionShutdownAsync();
+                });
+        }
+
+        [ConditionalFact(nameof(SupportsAlpn))]
         public async Task DataFrame_TooLong_ConnectionError()
         {
             using (var server = Http2LoopbackServer.CreateServer())