From b8e7cbad020184237e082d921f7dae5d21df1f28 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 20 Mar 2019 08:33:26 -0700 Subject: [PATCH] Remove Out-Of-Process test site fixture and make deployer check physical (#8659) --- .../CompressionTests.cs | 52 ++++++++++------ .../ServerAbortTests.cs | 61 ++++++++++--------- .../Utilities/IISTestSiteCollection.cs | 13 ---- .../Utilities/IISTestSiteFixture.cs | 27 -------- .../BackwardsCompatibilityTests.cs | 4 +- .../IntegrationTesting.IIS/src/IISDeployer.cs | 10 ++- 6 files changed, 74 insertions(+), 93 deletions(-) diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/CompressionTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/CompressionTests.cs index 5908caa4a9..262d3ff59c 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/CompressionTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/CompressionTests.cs @@ -5,41 +5,53 @@ using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; +using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { - [Collection(IISCompressionSiteCollection.Name)] - public abstract class CompressionTests : FixtureLoggedTest + [Collection(PublishedSitesCollection.Name)] + public class CompressionTests : IISFunctionalTestBase { - private readonly IISTestSiteFixture _fixture; - - [Collection(IISTestSiteCollection.Name)] - public class InProc: CompressionTests + public CompressionTests(PublishedSitesFixture fixture) : base(fixture) { - public InProc(IISTestSiteFixture fixture) : base(fixture) { } - } - - [Collection(OutOfProcessTestSiteCollection.Name)] - public class OutOfProcess: CompressionTests - { - public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { } - } - - protected CompressionTests(IISTestSiteFixture fixture) : base(fixture) - { - _fixture = fixture; } [ConditionalFact] - public async Task PassesThroughCompression() + public async Task PassesThroughCompressionOutOfProcess() { + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); + + var deploymentResult = await DeployAsync(deploymentParameters); + var request = new HttpRequestMessage(HttpMethod.Get, "/CompressedData"); request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); - var response = await _fixture.Client.SendAsync(request); + var response = await deploymentResult.HttpClient.SendAsync(request); + Assert.Equal("gzip", response.Content.Headers.ContentEncoding.Single()); + Assert.Equal( + new byte[] { + 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x0A, 0x63, 0x60, 0xA0, 0x3D, 0x00, 0x00, + 0xCA, 0xC6, 0x88, 0x99, 0x64, 0x00, 0x00, 0x00 }, + await response.Content.ReadAsByteArrayAsync()); + } + + [ConditionalFact] + public async Task PassesThroughCompressionInProcess() + { + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.InProcess); + + var deploymentResult = await DeployAsync(deploymentParameters); + + var request = new HttpRequestMessage(HttpMethod.Get, "/CompressedData"); + + request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); + + var response = await deploymentResult.HttpClient.SendAsync(request); Assert.Equal("gzip", response.Content.Headers.ContentEncoding.Single()); Assert.Equal( new byte[] { diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ServerAbortTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ServerAbortTests.cs index dbfe85ab19..1e3603aef4 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/ServerAbortTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/ServerAbortTests.cs @@ -4,51 +4,52 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Testing.xunit; using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { - public abstract class ServerAbortTests: FixtureLoggedTest + [Collection(PublishedSitesCollection.Name)] + public class ServerAbortOutOfProcessTests : IISFunctionalTestBase { - private readonly IISTestSiteFixture _fixture; - - [Collection(IISTestSiteCollection.Name)] - public class InProc: ServerAbortTests + public ServerAbortOutOfProcessTests(PublishedSitesFixture fixture) : base(fixture) { - public InProc(IISTestSiteFixture fixture) : base(fixture) { } - } - - [Collection(OutOfProcessTestSiteCollection.Name)] - public class OutOfProcess: ServerAbortTests - { - public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { } - } - - protected ServerAbortTests(IISTestSiteFixture fixture) : base(fixture) - { - _fixture = fixture; } [ConditionalFact] - public async Task ClosesConnectionOnServerAbort() + public async Task ClosesConnectionOnServerAbortOutOfProcess() { try { - var response = await _fixture.Client.GetAsync("/Abort").DefaultTimeout(); + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess); - // 502 is expected for outofproc but not for inproc - if (_fixture.DeploymentResult.DeploymentParameters.HostingModel == HostingModel.OutOfProcess) - { - Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode); - // 0x80072f78 ERROR_HTTP_INVALID_SERVER_RESPONSE The server returned an invalid or unrecognized response - Assert.Contains("0x80072f78", await response.Content.ReadAsStringAsync()); - } - else - { - Assert.True(false, "Should not reach here"); - } + var deploymentResult = await DeployAsync(deploymentParameters); + + var response = await deploymentResult.HttpClient.GetAsync("/Abort").DefaultTimeout(); + + Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode); + // 0x80072f78 ERROR_HTTP_INVALID_SERVER_RESPONSE The server returned an invalid or unrecognized response + Assert.Contains("0x80072f78", await response.Content.ReadAsStringAsync()); + } + catch (HttpRequestException) + { + // Connection reset is expected + } + } + + [ConditionalFact] + public async Task ClosesConnectionOnServerAbortInProcess() + { + try + { + var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.InProcess); + + var deploymentResult = await DeployAsync(deploymentParameters); + var response = await deploymentResult.HttpClient.GetAsync("/Abort").DefaultTimeout(); + + Assert.True(false, "Should not reach here"); } catch (HttpRequestException) { diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs index 562d63adbe..8d53affc98 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs @@ -13,17 +13,4 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { public const string Name = nameof(IISTestSiteCollection); } - - [CollectionDefinition(Name)] - public class OutOfProcessTestSiteCollection : ICollectionFixture - { - public const string Name = nameof(OutOfProcessTestSiteCollection); - } - - [CollectionDefinition(Name)] - public class OutOfProcessV1TestSiteCollection : ICollectionFixture - { - public const string Name = nameof(OutOfProcessV1TestSiteCollection); - } - } diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteFixture.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteFixture.cs index ff966acc48..01d5b2b525 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteFixture.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Utilities/IISTestSiteFixture.cs @@ -11,33 +11,6 @@ using Microsoft.Extensions.Logging.Testing; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { - public class OutOfProcessTestSiteFixture : IISTestSiteFixture - { - public OutOfProcessTestSiteFixture() : base(Configure) - { - } - - private static void Configure(IISDeploymentParameters deploymentParameters) - { - deploymentParameters.ApplicationPublisher = new PublishedApplicationPublisher(Helpers.GetOutOfProcessTestSitesName());; - deploymentParameters.HostingModel = HostingModel.OutOfProcess; - } - } - - public class OutOfProcessV1TestSiteFixture : IISTestSiteFixture - { - public OutOfProcessV1TestSiteFixture() : base(Configure) - { - } - - private static void Configure(IISDeploymentParameters deploymentParameters) - { - deploymentParameters.ApplicationPublisher = new PublishedApplicationPublisher(Helpers.GetOutOfProcessTestSitesName());; - deploymentParameters.ApplicationPath = Helpers.GetOutOfProcessTestSitesName(); - deploymentParameters.HostingModel = HostingModel.OutOfProcess; - } - } - public class IISTestSiteFixture : IDisposable { private ApplicationDeployer _deployer; diff --git a/src/Servers/IIS/IIS/test/IIS.BackwardsCompatibility.FunctionalTests/BackwardsCompatibilityTests.cs b/src/Servers/IIS/IIS/test/IIS.BackwardsCompatibility.FunctionalTests/BackwardsCompatibilityTests.cs index 489a10f390..807e01389b 100644 --- a/src/Servers/IIS/IIS/test/IIS.BackwardsCompatibility.FunctionalTests/BackwardsCompatibilityTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.BackwardsCompatibility.FunctionalTests/BackwardsCompatibilityTests.cs @@ -22,8 +22,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [ConditionalFact] public async Task CheckBackwardsCompatibilityIsUsed() { - var response = await _fixture.Client.GetAsync("/HelloWorld"); + + Assert.True(response.IsSuccessStatusCode); + _fixture.DeploymentResult.HostProcess.Refresh(); var handles = _fixture.DeploymentResult.HostProcess.Modules; diff --git a/src/Servers/IIS/IntegrationTesting.IIS/src/IISDeployer.cs b/src/Servers/IIS/IntegrationTesting.IIS/src/IISDeployer.cs index c98b6b83ed..0f551b7658 100644 --- a/src/Servers/IIS/IntegrationTesting.IIS/src/IISDeployer.cs +++ b/src/Servers/IIS/IntegrationTesting.IIS/src/IISDeployer.cs @@ -218,11 +218,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS AddTemporaryAppHostConfig(contentRoot, port); - WaitUntilSiteStarted(); + WaitUntilSiteStarted(contentRoot); } } - private void WaitUntilSiteStarted() + private void WaitUntilSiteStarted(string contentRoot) { ServiceController serviceController = new ServiceController("w3svc"); Logger.LogInformation("W3SVC status " + serviceController.Status); @@ -241,6 +241,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS var site = serverManager.Sites.Single(); var appPool = serverManager.ApplicationPools.Single(); + var actualPath = site.Applications.FirstOrDefault().VirtualDirectories.Single().PhysicalPath; + if (actualPath != contentRoot) + { + throw new InvalidOperationException($"Wrong physical path. Expected: {contentRoot} Actual: {actualPath}"); + } + if (appPool.State != ObjectState.Started && appPool.State != ObjectState.Starting) { var state = appPool.Start();