mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
Lately, the CI system and test server infrastructure has been overloaded with many PRs. This is causing many networking tests to randomly fail due to resource exhaustion caused by so many simultaneous PR runs on the same CI machines. This occurrs not only when using an external test server endpoint (corefx-net.cloudapp.net) but also loopback servers. To improve engineering efficiency for the team, we are moving most of the tests in the networking libraries from the default CI runs (innerloop). For developers working on networking libraries, the networking tests can be run by invoking the "outerloop" tests. We will not be allowing any merges of PRs in the networking libraries unless the outerloop tests are also run by the developer. This affects tests in the following libraries right now: * System.Net.Http * System.Net.Http.WinHttpHandler * System.Net.Sockets * System.Net.Security * System.Net.WebSockets.Client I will be working on fine tuning these exclusions (issue dotnet/corefx#11345) to try to bring back tests into the innerloop runs when we have begun to address the infrastructure issues. Commit migrated from https://github.com/dotnet/corefx/commit/defbb8afd11b317f6b5cc2f4422a03d701b6dba3
122 lines
5.0 KiB
C#
122 lines
5.0 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Test.Common;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
// Can't use "WinHttpHandler.Functional.Tests" in namespace as it won't compile.
|
|
// WinHttpHandler is a class and not a namespace and can't be part of namespace paths.
|
|
namespace System.Net.Http.WinHttpHandlerFunctional.Tests
|
|
{
|
|
// Note: Disposing the HttpClient object automatically disposes the handler within. So, it is not necessary
|
|
// to separately Dispose (or have a 'using' statement) for the handler.
|
|
public class WinHttpHandlerTest
|
|
{
|
|
// TODO: This is a placeholder until GitHub Issue #2383 gets resolved.
|
|
private const string SlowServer = "http://httpbin.org/drip?numbytes=1&duration=1&delay=40&code=200";
|
|
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
public WinHttpHandlerTest(ITestOutputHelper output)
|
|
{
|
|
_output = output;
|
|
}
|
|
|
|
[OuterLoop] // TODO: Issue #11345
|
|
[Fact]
|
|
public void SendAsync_SimpleGet_Success()
|
|
{
|
|
var handler = new WinHttpHandler();
|
|
using (var client = new HttpClient(handler))
|
|
{
|
|
// TODO: This is a placeholder until GitHub Issue #2383 gets resolved.
|
|
var response = client.GetAsync(Configuration.Http.RemoteEchoServer).Result;
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
|
_output.WriteLine(responseContent);
|
|
}
|
|
}
|
|
|
|
[OuterLoop] // TODO: Issue #11345
|
|
[Theory]
|
|
[InlineData(CookieUsePolicy.UseInternalCookieStoreOnly, "cookieName1", "cookieValue1")]
|
|
[InlineData(CookieUsePolicy.UseSpecifiedCookieContainer, "cookieName2", "cookieValue2")]
|
|
public async Task GetAsync_RedirectResponseHasCookie_CookieSentToFinalUri(
|
|
CookieUsePolicy cookieUsePolicy,
|
|
string cookieName,
|
|
string cookieValue)
|
|
{
|
|
Uri uri = Configuration.Http.RedirectUriForDestinationUri(false, 302, Configuration.Http.RemoteEchoServer, 1);
|
|
var handler = new WinHttpHandler();
|
|
handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
|
|
handler.CookieUsePolicy = cookieUsePolicy;
|
|
if (cookieUsePolicy == CookieUsePolicy.UseSpecifiedCookieContainer)
|
|
{
|
|
handler.CookieContainer = new CookieContainer();
|
|
}
|
|
|
|
using (HttpClient client = new HttpClient(handler))
|
|
{
|
|
client.DefaultRequestHeaders.Add(
|
|
"X-SetCookie",
|
|
string.Format("{0}={1};Path=/", cookieName, cookieValue));
|
|
using (HttpResponseMessage httpResponse = await client.GetAsync(uri))
|
|
{
|
|
string responseText = await httpResponse.Content.ReadAsStringAsync();
|
|
_output.WriteLine(responseText);
|
|
Assert.True(JsonMessageContainsKeyValue(responseText, cookieName, cookieValue));
|
|
}
|
|
}
|
|
}
|
|
|
|
[OuterLoop] // TODO: Issue #11345
|
|
[Fact]
|
|
[OuterLoop]
|
|
public async Task SendAsync_SlowServerAndCancel_ThrowsTaskCanceledException()
|
|
{
|
|
var handler = new WinHttpHandler();
|
|
using (var client = new HttpClient(handler))
|
|
{
|
|
var cts = new CancellationTokenSource();
|
|
Task<HttpResponseMessage> t = client.GetAsync(SlowServer, cts.Token);
|
|
|
|
await Task.Delay(500);
|
|
cts.Cancel();
|
|
|
|
AggregateException ag = Assert.Throws<AggregateException>(() => t.Wait());
|
|
Assert.IsType<TaskCanceledException>(ag.InnerException);
|
|
}
|
|
}
|
|
|
|
[OuterLoop] // TODO: Issue #11345
|
|
[Fact]
|
|
[OuterLoop]
|
|
public void SendAsync_SlowServerRespondsAfterDefaultReceiveTimeout_ThrowsHttpRequestException()
|
|
{
|
|
var handler = new WinHttpHandler();
|
|
using (var client = new HttpClient(handler))
|
|
{
|
|
Task<HttpResponseMessage> t = client.GetAsync(SlowServer);
|
|
|
|
AggregateException ag = Assert.Throws<AggregateException>(() => t.Wait());
|
|
Assert.IsType<HttpRequestException>(ag.InnerException);
|
|
}
|
|
}
|
|
|
|
public static bool JsonMessageContainsKeyValue(string message, string key, string value)
|
|
{
|
|
// TODO: Merge with System.Net.Http TestHelper class as part of GitHub Issue #4989.
|
|
string pattern = string.Format(@"""{0}"": ""{1}""", key, value);
|
|
return message.Contains(pattern);
|
|
}
|
|
}
|
|
}
|