Change EstablishConnectionAndProcessOneRequestAsync test method to use WhenAllOrAnyFa...
authorStephen Toub <stoub@microsoft.com>
Tue, 11 Jun 2019 20:01:14 +0000 (13:01 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2019 20:01:14 +0000 (13:01 -0700)
* Change EstablishConnectionAndProcessOneRequestAsync test method to use WhenAllOrAnyFailed

CI is currently hanging when the client operation fails in a way that the server never hears about the request, and waits forever.

* Address PR feedback

Commit migrated from https://github.com/dotnet/corefx/commit/0b5479dde70fc565c5edefac4259578865496e84

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

index 811ba1a..a99ded6 100644 (file)
@@ -696,17 +696,26 @@ namespace System.Net.Http.Functional.Tests
 
         private static async Task<int> EstablishConnectionAndProcessOneRequestAsync(HttpClient client, Http2LoopbackServer server)
         {
-            // Establish connection and send initial request/response to ensure connection is available for subsequent use
-            Task<HttpResponseMessage> sendTask = client.GetAsync(server.Address);
-
-            await server.EstablishConnectionAsync();
-
-            int streamId = await server.ReadRequestHeaderAsync();
-            await server.SendDefaultResponseAsync(streamId);
+            int streamId = -1;
 
-            HttpResponseMessage response = await sendTask;
-            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
-            Assert.Equal(0, (await response.Content.ReadAsByteArrayAsync()).Length);
+            // Establish connection and send initial request/response to ensure connection is available for subsequent use
+            await new[]
+            {
+                Task.Run(async () =>
+                {
+                    using (HttpResponseMessage response = await client.GetAsync(server.Address))
+                    {
+                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+                        Assert.Equal(0, (await response.Content.ReadAsByteArrayAsync()).Length);
+                    }
+                }),
+                Task.Run(async () =>
+                {
+                    await server.EstablishConnectionAsync();
+                    streamId = await server.ReadRequestHeaderAsync();
+                    await server.SendDefaultResponseAsync(streamId);
+                })
+            }.WhenAllOrAnyFailed(TestHelper.PassingTestTimeoutMilliseconds);
 
             return streamId;
         }