Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily disable test failing on OSX #66761

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvalidOperationException>(() => client.BaseAddress = null);
Expand All @@ -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))
Expand All @@ -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
}))))
Expand All @@ -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);
Expand All @@ -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<HttpResponseMessage>(null))))
using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult<HttpResponseMessage>(null))))
{
await Assert.ThrowsAnyAsync<InvalidOperationException>(() => client.GetStringAsync(CreateFakeUri()));
}
Expand All @@ -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<byte>(), await client.GetByteArrayAsync(CreateFakeUri()));
Expand Down Expand Up @@ -724,7 +725,8 @@ public void Timeout_TooShort_AllPendingOperationsCanceled(HttpCompletionOption c
{
client.Timeout = TimeSpan.FromMilliseconds(10);
Task<HttpResponseMessage>[] tasks = Enumerable.Range(0, 3).Select(_ => client.GetAsync(CreateFakeUri(), completionOption)).ToArray();
Assert.All(tasks, task => {
Assert.All(tasks, task =>
{
OperationCanceledException e = Assert.ThrowsAny<OperationCanceledException>(() => task.GetAwaiter().GetResult());
TimeoutException timeoutException = (TimeoutException)e.InnerException;
Assert.NotNull(timeoutException);
Expand Down Expand Up @@ -787,7 +789,7 @@ public async Task Timeout_SetTo30AndGetResponseQuickly_Success()
[Fact]
public void DefaultProxy_SetNull_Throws()
{
Assert.Throws<ArgumentNullException>(() => HttpClient.DefaultProxy = null );
Assert.Throws<ArgumentNullException>(() => HttpClient.DefaultProxy = null);
}

[Fact]
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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>(stream =>
{
for (int i = 0; i < 100; ++i)
Expand All @@ -989,13 +994,13 @@ await LoopbackServer.CreateClientAndServerAsync(
Assert.IsNotType<TimeoutException>(ex.InnerException);
},
async server =>
{
{
await server.AcceptConnectionAsync(async connection =>
{
try
{
await connection.ReadRequestHeaderAsync();
cts.Cancel();
cts.Cancel();
await connection.ReadRequestBodyAsync();
}
catch { }
Expand All @@ -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>(stream =>
{
Thread.Sleep(TimeSpan.FromSeconds(0.5));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1093,7 +1102,7 @@ await server.AcceptConnectionAsync(async connection =>
}
catch { }
});
});
});
}

[Fact]
Expand Down Expand Up @@ -1163,7 +1172,7 @@ await HttpAgnosticLoopbackServer.CreateClientAndServerAsync(
Version = requestVersion,
VersionPolicy = versionPolicy
};

using HttpClientHandler handler = CreateHttpClientHandler();
if (useSsl)
{
Expand Down Expand Up @@ -1199,7 +1208,7 @@ await HttpAgnosticLoopbackServer.CreateClientAndServerAsync(
{
UseSsl = useSsl,
ClearTextVersion = serverVersion,
SslApplicationProtocols = serverVersion.Major >= 2 ? new List<SslApplicationProtocol>{ SslApplicationProtocol.Http2, SslApplicationProtocol.Http11 } : null
SslApplicationProtocols = serverVersion.Major >= 2 ? new List<SslApplicationProtocol> { SslApplicationProtocol.Http2, SslApplicationProtocol.Http11 } : null
});
}

Expand Down