115 lines
4.7 KiB
C#
115 lines
4.7 KiB
C#
// 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;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Testing;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
using Xunit.Sdk;
|
|
|
|
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|
{
|
|
public class UpgradeFeatureDetectionTests : LoggedTest
|
|
{
|
|
private string _isWebsocketsSupported = Environment.OSVersion.Version >= new Version(6, 2) ? "Enabled" : "Disabled";
|
|
|
|
public UpgradeFeatureDetectionTests(ITestOutputHelper output) : base(output)
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public Task UpgradeFeatureDetectionEnabled_InProcess_IISExpress_CoreClr_x64_Portable()
|
|
{
|
|
return UpgradeFeatureDetectionDeployer(RuntimeFlavor.CoreClr,
|
|
ApplicationType.Portable,
|
|
"AppHostConfig/WebsocketsNotSupported.config",
|
|
Helpers.GetInProcessTestSitesPath(),
|
|
"Disabled");
|
|
}
|
|
|
|
[Fact]
|
|
public Task UpgradeFeatureDetectionDisabled_InProcess_IISExpress_CoreClr_x64_Portable()
|
|
{
|
|
return UpgradeFeatureDetectionDeployer(RuntimeFlavor.CoreClr,
|
|
ApplicationType.Portable,
|
|
"AppHostConfig/Http.config",
|
|
Helpers.GetInProcessTestSitesPath(),
|
|
_isWebsocketsSupported);
|
|
}
|
|
|
|
[Fact]
|
|
public Task UpgradeFeatureDetectionEnabled_OutOfProcess_IISExpress_CoreClr_x64_Portable()
|
|
{
|
|
return UpgradeFeatureDetectionDeployer(RuntimeFlavor.CoreClr,
|
|
ApplicationType.Portable,
|
|
"AppHostConfig/WebsocketsNotSupported.config",
|
|
Helpers.GetOutOfProcessTestSitesPath(),
|
|
"Disabled");
|
|
}
|
|
|
|
[Fact]
|
|
public Task UpgradeFeatureDetectionDisabled_OutOfProcess_IISExpress_CoreClr_x64_Portable()
|
|
{
|
|
return UpgradeFeatureDetectionDeployer(RuntimeFlavor.CoreClr,
|
|
ApplicationType.Portable,
|
|
"AppHostConfig/Http.config",
|
|
Helpers.GetOutOfProcessTestSitesPath(),
|
|
_isWebsocketsSupported);
|
|
}
|
|
|
|
private async Task UpgradeFeatureDetectionDeployer(RuntimeFlavor runtimeFlavor,
|
|
ApplicationType applicationType,
|
|
string configPath,
|
|
string sitePath,
|
|
string expected)
|
|
{
|
|
var serverType = ServerType.IISExpress;
|
|
var architecture = RuntimeArchitecture.x64;
|
|
var testName = $"HelloWorld_{runtimeFlavor}";
|
|
using (StartLog(out var loggerFactory, testName))
|
|
{
|
|
var logger = loggerFactory.CreateLogger("HelloWorldTest");
|
|
|
|
var deploymentParameters = new DeploymentParameters(sitePath, serverType, runtimeFlavor, architecture)
|
|
{
|
|
EnvironmentName = "UpgradeFeatureDetection", // Will pick the Start class named 'StartupHelloWorld',
|
|
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText(configPath) : null,
|
|
SiteName = "HttpTestSite", // This is configured in the Http.config
|
|
TargetFramework = "netcoreapp2.1",
|
|
ApplicationType = applicationType,
|
|
ANCMVersion = ANCMVersion.AspNetCoreModuleV2
|
|
};
|
|
|
|
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
|
|
{
|
|
var deploymentResult = await deployer.DeployAsync();
|
|
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
|
|
|
|
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
|
|
var response = await RetryHelper.RetryRequest(() =>
|
|
{
|
|
return deploymentResult.HttpClient.GetAsync("UpgradeFeatureDetection");
|
|
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
|
|
|
|
var responseText = await response.Content.ReadAsStringAsync();
|
|
try
|
|
{
|
|
Assert.Equal(expected, responseText);
|
|
}
|
|
catch (XunitException)
|
|
{
|
|
logger.LogWarning(response.ToString());
|
|
logger.LogWarning(responseText);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|