From 573d51dccb4fb600d087e5c3b44b1c62eb4327c3 Mon Sep 17 00:00:00 2001 From: Radek Zikmund <32671551+rzikm@users.noreply.github.com> Date: Thu, 17 Mar 2022 18:49:03 +0100 Subject: [PATCH] Temporarily disable HttpClientTest.GetContentAsync_WhenCanNotConnect_ExceptionContainsHostInfo on OSX (#66761) --- .../tests/FunctionalTests/HttpClientTest.cs | 73 +++++++++++-------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs index 9b697a58dcc27..41cc4758882a6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs @@ -160,7 +160,7 @@ public async Task MaxResponseContentBufferSize_ThrowsIfTooSmallForContent(int ma [Fact] public async Task Properties_CantChangeAfterOperation_Throws() { - using (var client = new HttpClient(new CustomResponseHandler((r,c) => Task.FromResult(new HttpResponseMessage())))) + using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage())))) { (await client.GetAsync(CreateFakeUri())).Dispose(); Assert.Throws(() => client.BaseAddress = null); @@ -185,7 +185,7 @@ public void GetAsync_NoBaseAddress_InvalidUri_ThrowsException(string uri) [InlineData("/")] public async Task GetAsync_BaseAddress_ValidUri_Success(string uri) { - using (var client = new HttpClient(new CustomResponseHandler((r,c) => Task.FromResult(new HttpResponseMessage())))) + using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage())))) { client.BaseAddress = new Uri(CreateFakeUri()); using (HttpResponseMessage response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead)) @@ -201,7 +201,7 @@ public async Task GetAsync_BaseAddress_ValidUri_Success(string uri) public async Task GetContentAsync_ErrorStatusCode_ExpectedExceptionThrown(bool withResponseContent) { using (var client = new HttpClient(new CustomResponseHandler( - (r,c) => Task.FromResult(new HttpResponseMessage(HttpStatusCode.BadRequest) + (r, c) => Task.FromResult(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = withResponseContent ? new ByteArrayContent(new byte[1]) : null })))) @@ -222,6 +222,7 @@ public async Task GetContentAsync_ErrorStatusCode_ExpectedExceptionThrown(bool w [Fact] [OuterLoop("Failing connection attempts take long on windows")] [SkipOnPlatform(TestPlatforms.Browser, "Socket is not supported on Browser")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/66692", TestPlatforms.OSX)] public async Task GetContentAsync_WhenCanNotConnect_ExceptionContainsHostInfo() { using Socket portReserver = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -237,7 +238,7 @@ public async Task GetContentAsync_WhenCanNotConnect_ExceptionContainsHostInfo() [Fact] public async Task GetContentAsync_NullResponse_Throws() { - using (var client = new HttpClient(new CustomResponseHandler((r,c) => Task.FromResult(null)))) + using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(null)))) { await Assert.ThrowsAnyAsync(() => client.GetStringAsync(CreateFakeUri())); } @@ -246,7 +247,7 @@ public async Task GetContentAsync_NullResponse_Throws() [Fact] public async Task GetContentAsync_NullResponseContent_ReturnsDefaultValue() { - using (var client = new HttpClient(new CustomResponseHandler((r,c) => Task.FromResult(new HttpResponseMessage() { Content = null })))) + using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage() { Content = null })))) { Assert.Same(string.Empty, await client.GetStringAsync(CreateFakeUri())); Assert.Same(Array.Empty(), await client.GetByteArrayAsync(CreateFakeUri())); @@ -724,7 +725,8 @@ public void Timeout_TooShort_AllPendingOperationsCanceled(HttpCompletionOption c { client.Timeout = TimeSpan.FromMilliseconds(10); Task[] tasks = Enumerable.Range(0, 3).Select(_ => client.GetAsync(CreateFakeUri(), completionOption)).ToArray(); - Assert.All(tasks, task => { + Assert.All(tasks, task => + { OperationCanceledException e = Assert.ThrowsAny(() => task.GetAwaiter().GetResult()); TimeoutException timeoutException = (TimeoutException)e.InnerException; Assert.NotNull(timeoutException); @@ -787,7 +789,7 @@ public async Task Timeout_SetTo30AndGetResponseQuickly_Success() [Fact] public void DefaultProxy_SetNull_Throws() { - Assert.Throws(() => HttpClient.DefaultProxy = null ); + Assert.Throws(() => HttpClient.DefaultProxy = null); } [Fact] @@ -877,27 +879,27 @@ public void Send_SingleThread_Succeeds(HttpCompletionOption completionOption) { int currentThreadId = Environment.CurrentManagedThreadId; - var client = new HttpClient(new CustomResponseHandler((r, c) => + var client = new HttpClient(new CustomResponseHandler((r, c) => { Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); return Task.FromResult(new HttpResponseMessage() + { + Content = new CustomContent(stream => { - Content = new CustomContent(stream => - { - Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); - }) - }); + Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); + }) + }); })); using (client) { HttpResponseMessage response = client.Send(new HttpRequestMessage(HttpMethod.Get, CreateFakeUri()) + { + Content = new CustomContent(stream => { - Content = new CustomContent(stream => - { - Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); - }) - }, completionOption); - + Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); + }) + }, completionOption); + Stream contentStream = response.Content.ReadAsStream(); Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); } @@ -925,7 +927,8 @@ await LoopbackServer.CreateClientAndServerAsync( using HttpClient httpClient = CreateHttpClient(); - HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) { + HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) + { Content = new CustomContent(stream => { Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); @@ -934,7 +937,7 @@ await LoopbackServer.CreateClientAndServerAsync( }, completionOption); Stream contentStream = response.Content.ReadAsStream(); - Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); + Assert.Equal(currentThreadId, Environment.CurrentManagedThreadId); using (StreamReader sr = new StreamReader(contentStream)) { Assert.Equal(content, sr.ReadToEnd()); @@ -967,11 +970,13 @@ public async Task Send_CancelledRequestContent_Throws() await LoopbackServer.CreateClientAndServerAsync( async uri => { - var sendTask = Task.Run(() => { + var sendTask = Task.Run(() => + { using HttpClient httpClient = CreateHttpClient(); httpClient.Timeout = TimeSpan.FromMinutes(2); - HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) { + HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) + { Content = new CustomContent(new Action(stream => { for (int i = 0; i < 100; ++i) @@ -989,13 +994,13 @@ await LoopbackServer.CreateClientAndServerAsync( Assert.IsNotType(ex.InnerException); }, async server => - { + { await server.AcceptConnectionAsync(async connection => { try { await connection.ReadRequestHeaderAsync(); - cts.Cancel(); + cts.Cancel(); await connection.ReadRequestBodyAsync(); } catch { } @@ -1011,11 +1016,13 @@ public async Task Send_TimeoutRequestContent_Throws() await LoopbackServer.CreateClientAndServerAsync( async uri => { - var sendTask = Task.Run(() => { + var sendTask = Task.Run(() => + { using HttpClient httpClient = CreateHttpClient(); httpClient.Timeout = TimeSpan.FromSeconds(0.5); - HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) { + HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) + { Content = new CustomContent(new Action(stream => { Thread.Sleep(TimeSpan.FromSeconds(0.5)); @@ -1058,11 +1065,13 @@ public async Task Send_CancelledResponseContent_Throws() await LoopbackServer.CreateClientAndServerAsync( async uri => { - var sendTask = Task.Run(() => { + var sendTask = Task.Run(() => + { using HttpClient httpClient = CreateHttpClient(); httpClient.Timeout = TimeSpan.FromMinutes(2); - HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) { + HttpResponseMessage response = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, uri) + { Content = new CustomContent(stream => { stream.Write(Encoding.UTF8.GetBytes(content)); @@ -1093,7 +1102,7 @@ await server.AcceptConnectionAsync(async connection => } catch { } }); - }); + }); } [Fact] @@ -1163,7 +1172,7 @@ await HttpAgnosticLoopbackServer.CreateClientAndServerAsync( Version = requestVersion, VersionPolicy = versionPolicy }; - + using HttpClientHandler handler = CreateHttpClientHandler(); if (useSsl) { @@ -1199,7 +1208,7 @@ await HttpAgnosticLoopbackServer.CreateClientAndServerAsync( { UseSsl = useSsl, ClearTextVersion = serverVersion, - SslApplicationProtocols = serverVersion.Major >= 2 ? new List{ SslApplicationProtocol.Http2, SslApplicationProtocol.Http11 } : null + SslApplicationProtocols = serverVersion.Major >= 2 ? new List { SslApplicationProtocol.Http2, SslApplicationProtocol.Http11 } : null }); }