-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Fix and test HttpSys delegation #36677
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
Changes from all commits
169b326
682733f
703709e
3d02cc3
c55fcb3
35324a3
4c3b0b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net.Http; | ||
using Microsoft.AspNetCore.Server.IntegrationTesting; | ||
using Microsoft.AspNetCore.Testing; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Server.HttpSys.NonHelixTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why we don't want these to run on helix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We never figured out how to make them work there. #8247 |
||
{ | ||
public class DelegateOutOfProcTests : LoggedTest | ||
{ | ||
public DelegateOutOfProcTests(ITestOutputHelper output) : base(output) { } | ||
|
||
[ConditionalFact] | ||
[DelegateSupportedCondition(true)] | ||
public async Task CanDelegateOutOfProcess() | ||
{ | ||
using var _ = StartLog(out var loggerFactory); | ||
|
||
var logger = loggerFactory.CreateLogger("CanDelegateOutOfProcess"); | ||
|
||
// https://github.com/dotnet/aspnetcore/issues/8247 | ||
#pragma warning disable 0618 | ||
var applicationPath = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("HttpSysServer"), "test", "testassets", | ||
"DelegationSite"); | ||
#pragma warning restore 0618 | ||
|
||
var deploymentParameters = new DeploymentParameters( | ||
applicationPath, | ||
ServerType.HttpSys, | ||
RuntimeFlavor.CoreClr, | ||
RuntimeArchitecture.x64) | ||
{ | ||
EnvironmentName = "Testing", | ||
TargetFramework = Tfm.Default, | ||
ApplicationType = ApplicationType.Portable, | ||
PublishApplicationBeforeDeployment = true, | ||
StatusMessagesEnabled = true | ||
}; | ||
|
||
var queueName = Guid.NewGuid().ToString(); | ||
deploymentParameters.EnvironmentVariables["queue"] = queueName; | ||
|
||
using var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory); | ||
var deploymentResult = await deployer.DeployAsync().DefaultTimeout(); | ||
|
||
// Make sure the deployment really worked | ||
var responseString = await deploymentResult.HttpClient.GetStringAsync("").DefaultTimeout(); | ||
Assert.Equal("Hello from delegatee", responseString); | ||
|
||
DelegationRule destination = default; | ||
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext => | ||
{ | ||
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>(); | ||
delegateFeature.DelegateRequest(destination); | ||
return Task.CompletedTask; | ||
}); | ||
|
||
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>(); | ||
using (destination = delegationProperty.CreateDelegationRule(queueName, deploymentResult.ApplicationBaseUri)) | ||
{ | ||
// Send a request to the delegator that gets transfered to the delegatee in the other process. | ||
using var client = new HttpClient(); | ||
responseString = await client.GetStringAsync(delegatorAddress).DefaultTimeout(); | ||
Assert.Equal("Hello from delegatee", responseString); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen on older OSes that don't have this API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP_INITIALIZE_CONFIG isn't a new flag, I think it's been around forever. What changed is that HttpIsFeatureSupported now requires it.