-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase HttpClientHandler.MaxConnectionsPerServer to 64 to improve P…
…M UI performance in Visual Studio (#4798)
- Loading branch information
1 parent
c543930
commit 451713c
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/NuGet.Core.Tests/NuGet.Protocol.Tests/HttpHandlerResourceV3ProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NuGet.Configuration; | ||
using NuGet.Protocol.Core.Types; | ||
using NuGet.Test.Utility; | ||
using Xunit; | ||
|
||
namespace NuGet.Protocol.Tests | ||
{ | ||
public class HttpHandlerResourceV3ProviderTests | ||
{ | ||
private readonly string _testPackageSourceURL = "https://contoso.test/v3/index.json"; | ||
|
||
#if IS_DESKTOP | ||
[PlatformFact(Platform.Windows)] | ||
public async Task DefaultMaxHttpRequestsPerSourceIsForwardedToV3HttpClientHandler_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new List<INuGetResourceProvider>() { new HttpSourceResourceProvider(), new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.Equal(64, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
|
||
[PlatformTheory(Platform.Windows)] | ||
[InlineData(128)] | ||
[InlineData(256)] | ||
public async Task PackageSourceMaxHttpRequestsPerSourceIsForwardedToV3HttpClientHandler_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new List<INuGetResourceProvider>() { new HttpSourceResourceProvider(), new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.Equal(maxHttpRequestsPerSource, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
#elif IS_CORECLR | ||
|
||
[Theory] | ||
[InlineData(64)] | ||
[InlineData(128)] | ||
[InlineData(2)] | ||
public async Task PackageSourceMaxHttpRequestsPerSourceIsNotForwardedToV3HttpClientHandler_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpHandlerResourceV3Provider() }); | ||
|
||
// HttpSourceResourceProvider updates PackageSource.MaxHttpRequestsPerSource value for .NET Framework code paths | ||
// HttpSource constructor accepts a delegate that creates HttpHandlerResource and it stores the delegate in a private variable. | ||
// Hence used discard to ignore the return value and fetched HttpHandlerResource from the source repository to verify behavior. | ||
_ = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Act | ||
HttpHandlerResource httpHandlerResource = await sourceRepository.GetResourceAsync<HttpHandlerResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpHandlerResource); | ||
Assert.NotEqual(maxHttpRequestsPerSource, httpHandlerResource.ClientHandler.MaxConnectionsPerServer); | ||
} | ||
#endif | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
test/NuGet.Core.Tests/NuGet.Protocol.Tests/HttpSourceResourceProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
using NuGet.Configuration; | ||
using NuGet.Protocol.Core.Types; | ||
using NuGet.Test.Utility; | ||
using Xunit; | ||
|
||
namespace NuGet.Protocol.Tests | ||
{ | ||
public class HttpSourceResourceProviderTests | ||
{ | ||
private readonly string _testPackageSourceURL = "https://contoso.test/v3/index.json"; | ||
|
||
#if IS_DESKTOP | ||
[PlatformFact(Platform.Windows)] | ||
public async Task WhenMaxHttpRequestsPerSourceIsNotConfiguredThenItsValueIsSetToDefault_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(64, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
#elif IS_CORECLR | ||
[Fact] | ||
public async Task WhenMaxHttpRequestsPerSourceIsNotConfiguredThenItsValueWillNotBeUpdated_SuccessAsync() | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL); | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(0, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
#endif | ||
|
||
[PlatformTheory] | ||
[InlineData(128)] | ||
[InlineData(256)] | ||
public async Task WhenMaxHttpRequestsPerSourceIsConfiguredThenItsValueWillNotBeUpdated_SuccessAsync(int maxHttpRequestsPerSource) | ||
{ | ||
// Arrange | ||
var packageSource = new PackageSource(_testPackageSourceURL) { MaxHttpRequestsPerSource = maxHttpRequestsPerSource }; | ||
var sourceRepository = new SourceRepository(packageSource, new[] { new HttpSourceResourceProvider() }); | ||
|
||
// Act | ||
HttpSourceResource httpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(); | ||
|
||
// Assert | ||
Assert.NotNull(httpSourceResource); | ||
Assert.Equal(maxHttpRequestsPerSource, sourceRepository.PackageSource.MaxHttpRequestsPerSource); | ||
} | ||
} | ||
} |