Files
dotnet-runtime/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.MaxConnectionsPerServer.cs
T
Santiago Fernandez Madero ccdea37829 Update netfx alias to target .NET 4.7.2 (dotnet/corefx#28883)
* Change netfx to target .NET 4.7.1

* Fix CoreFx.Private.TestUtilities to not reference System.Runtime.InteropServices.RuntimeInformation which is now inbox in netfx

* Fix StackTrace.Tests to be built against netstandard and run against netfx inbox

* Fix ValueTuple configurations to support net461 and add netfx placeholder configuration since in net471 it is now inbox

* Fix projects' package configurations that had netfx (net461) to still support net461 and netfx as a buildconfigurations

* Disable failing tests when running on .NET 4.7.1

* Make netfx target net472 and merge with master

* Update ActiveIssue comments to issue number only

* Workaround packages tests due to not installed targeting pack

* Match NSSupportPackage version to CLI's

* Remove netstandard support lib bin placing to runtime and testhost for netfx, fix reference paths to match new package

* Run UpdateVSConfigurations after merging conflicts with the newly updated SDK projects

* Add net461 package configuration to System.CodeDom

* Add net461 package configuration to System.Configuration.ConfigurationManager

* Add net461 package configuration to System.Security.Cryptography.Xml

* Add net461 package configuration to System.Security.Permissions

* Add net461 package configuration to System.ServiceModel.Syndication


Commit migrated from https://github.com/dotnet/corefx/commit/faad2e63b35bed10fe18195987a413308b97eded
2018-07-10 15:04:27 -07:00

124 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.Linq;
using System.Net.Test.Common;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace System.Net.Http.Functional.Tests
{
using Configuration = System.Net.Test.Common.Configuration;
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "UAP connection management behavior is different due to WinRT")]
public abstract class HttpClientHandler_MaxConnectionsPerServer_Test : HttpClientTestBase
{
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "MaxConnectionsPerServer either returns two or int.MaxValue depending if ctor of HttpClientHandlerTest executed first. Disabling cause of random xunit execution order.")]
public void Default_ExpectedValue()
{
using (HttpClientHandler handler = CreateHttpClientHandler())
{
Assert.Equal(int.MaxValue, handler.MaxConnectionsPerServer);
}
}
[Theory]
[InlineData(0)]
[InlineData(-1)]
[ActiveIssue(28882, TargetFrameworkMonikers.NetFramework)]
public void Set_InvalidValues_Throws(int invalidValue)
{
using (HttpClientHandler handler = CreateHttpClientHandler())
{
Assert.Throws<ArgumentOutOfRangeException>(() => handler.MaxConnectionsPerServer = invalidValue);
}
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(int.MaxValue)]
[InlineData(int.MaxValue - 1)]
public void Set_ValidValues_Success(int validValue)
{
using (HttpClientHandler handler = CreateHttpClientHandler())
{
try
{
handler.MaxConnectionsPerServer = validValue;
}
catch (PlatformNotSupportedException)
{
// Some older libcurls used in some of our Linux CI systems don't support this
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
}
}
}
[Theory]
[InlineData(1, 5, false)]
[InlineData(1, 5, true)]
[InlineData(2, 2, false)]
[InlineData(2, 2, true)]
[InlineData(3, 2, false)]
[InlineData(3, 2, true)]
[InlineData(3, 5, false)]
public async Task GetAsync_MaxLimited_ConcurrentCallsStillSucceed(int maxConnections, int numRequests, bool secure)
{
using (HttpClientHandler handler = CreateHttpClientHandler())
using (var client = new HttpClient(handler))
{
handler.MaxConnectionsPerServer = maxConnections;
await Task.WhenAll(
from i in Enumerable.Range(0, numRequests)
select client.GetAsync(secure ? Configuration.Http.RemoteEchoServer : Configuration.Http.SecureRemoteEchoServer));
}
}
[OuterLoop("Relies on kicking off GC and waiting for finalizers")]
[Fact]
public async Task GetAsync_DontDisposeResponse_EventuallyUnblocksWaiters()
{
if (!UseSocketsHttpHandler)
{
// Issue #27067. Hang.
return;
}
await LoopbackServer.CreateServerAsync(async (server, uri) =>
{
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClient client = new HttpClient(handler))
{
handler.MaxConnectionsPerServer = 1;
// Let server handle two requests.
const string ResponseContent = "abcdefghijklmnopqrstuvwxyz";
Task serverTask1 = server.AcceptConnectionSendResponseAndCloseAsync(content: ResponseContent);
Task serverTask2 = server.AcceptConnectionSendResponseAndCloseAsync(content: ResponseContent);
// Make first request and drop the response, not explicitly disposing of it.
void MakeAndDropRequest() => client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); // separated out to enable GC of response
MakeAndDropRequest();
// A second request should eventually succeed, once the first one is cleaned up.
Task<HttpResponseMessage> secondResponse = client.GetAsync(uri);
Assert.True(SpinWait.SpinUntil(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
return secondResponse.IsCompleted;
}, 30 * 1000), "Expected second response to have completed");
await new[] { serverTask1, serverTask2, secondResponse }.WhenAllOrAnyFailed();
}
});
}
}
}