diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeploymentResult.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeploymentResult.cs index 4a9d881900..814a778c16 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeploymentResult.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeploymentResult.cs @@ -27,21 +27,9 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS { HostProcess = hostProcess; Logger = loggerFactory.CreateLogger(deploymentParameters.SiteName); - // SocketsHttpHandler isn't available in netstandard2.0 - RetryingHttpClient = CreateRetryClient(new HttpClientHandler()); HttpClient = CreateClient(new HttpClientHandler()); } - public HttpClient CreateRetryClient(HttpMessageHandler messageHandler) - { - var loggingHandler = new LoggingHandler(messageHandler, Logger); - var retryHandler = new RetryHandler(loggingHandler, Logger); - return new HttpClient(retryHandler) - { - BaseAddress = base.HttpClient.BaseAddress - }; - } - public HttpClient CreateClient(HttpMessageHandler messageHandler) { return new HttpClient(new LoggingHandler(messageHandler, Logger)) @@ -50,8 +38,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS }; } - public HttpClient RetryingHttpClient { get; set; } - public new HttpClient HttpClient { get; set; } } } diff --git a/test/Common.FunctionalTests/AppOfflineTests.cs b/test/Common.FunctionalTests/AppOfflineTests.cs index c191eea4c7..3e1580fcb9 100644 --- a/test/Common.FunctionalTests/AppOfflineTests.cs +++ b/test/Common.FunctionalTests/AppOfflineTests.cs @@ -42,6 +42,25 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests DeletePublishOutput(deploymentResult); } + [ConditionalTheory] + [InlineData(HostingModel.InProcess)] + [InlineData(HostingModel.OutOfProcess)] + public async Task LockedAppOfflineDroppedWhileSiteIsDown_SiteReturns503(HostingModel hostingModel) + { + var deploymentResult = await DeployApp(hostingModel); + + // Add app_offline without shared access + using (var stream = File.Open(Path.Combine(deploymentResult.ContentRoot, "app_offline.htm"), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)) + using (var writer = new StreamWriter(stream)) + { + await writer.WriteLineAsync("App if offline but you wouldn't see this message"); + await writer.FlushAsync(); + await AssertAppOffline(deploymentResult, ""); + } + + DeletePublishOutput(deploymentResult); + } + [ConditionalTheory] [InlineData(HostingModel.InProcess, 500, "500.0")] [InlineData(HostingModel.OutOfProcess, 502, "502.5")] @@ -259,7 +278,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests private static async Task AssertRunning(IISDeploymentResult deploymentResult) { - var response = await deploymentResult.RetryingHttpClient.GetAsync("HelloWorld"); + HttpResponseMessage response = null; + + for (var i = 0; i < 5 && response?.IsSuccessStatusCode != true; i++) + { + response = await deploymentResult.HttpClient.GetAsync("HelloWorld"); + await Task.Delay(RetryDelay); + } var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); diff --git a/test/Common.FunctionalTests/Inprocess/LoggingTests.cs b/test/Common.FunctionalTests/Inprocess/LoggingTests.cs index 6710fb7f47..0a19a90133 100644 --- a/test/Common.FunctionalTests/Inprocess/LoggingTests.cs +++ b/test/Common.FunctionalTests/Inprocess/LoggingTests.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - await deploymentResult.RetryingHttpClient.GetAsync("/"); + await deploymentResult.HttpClient.GetAsync("/"); AssertLogs(Path.Combine(deploymentResult.ContentRoot, "debug.txt")); } @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - await deploymentResult.RetryingHttpClient.GetAsync("/"); + await deploymentResult.HttpClient.GetAsync("/"); AssertLogs(Path.Combine(deploymentResult.ContentRoot, "aspnetcore-debug.log")); } @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests deploymentParameters.HandlerSettings["debugFile"] = ""; var deploymentResult = await DeployAsync(deploymentParameters); - await deploymentResult.RetryingHttpClient.GetAsync("/"); + await deploymentResult.HttpClient.GetAsync("/"); AssertLogs(Path.Combine(deploymentResult.ContentRoot, "aspnetcore-debug.log")); } @@ -186,7 +186,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("/"); + var response = await deploymentResult.HttpClient.GetAsync("/"); StopServer(); var logContents = File.ReadAllText(firstTempFile); diff --git a/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs b/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs index 980341dbc4..1234d368fc 100644 --- a/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs +++ b/test/Common.FunctionalTests/Inprocess/StartupExceptionTests.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync(path); + var response = await deploymentResult.HttpClient.GetAsync(path); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); @@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync(path); + var response = await deploymentResult.HttpClient.GetAsync(path); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); diff --git a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs index d2a56caea5..0b05ff54db 100644 --- a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs +++ b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("/HelloWorld"); + var response = await deploymentResult.HttpClient.GetAsync("/HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); diff --git a/test/Common.FunctionalTests/Utilities/Helpers.cs b/test/Common.FunctionalTests/Utilities/Helpers.cs index 77eb37d524..73d48fd6ca 100644 --- a/test/Common.FunctionalTests/Utilities/Helpers.cs +++ b/test/Common.FunctionalTests/Utilities/Helpers.cs @@ -25,11 +25,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests public static string GetInProcessTestSitesPath() => GetTestWebSitePath("InProcessWebSite"); public static string GetOutOfProcessTestSitesPath() => GetTestWebSitePath("OutOfProcessWebSite"); - + public static async Task AssertStarts(IISDeploymentResult deploymentResult, string path = "/HelloWorld") { - var response = await deploymentResult.RetryingHttpClient.GetAsync(path); + var response = await deploymentResult.HttpClient.GetAsync(path); var responseText = await response.Content.ReadAsStringAsync(); diff --git a/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs b/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs index af442c4521..333a7a055b 100644 --- a/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/AuthenticationTests.cs @@ -29,26 +29,26 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("/AuthenticationAnonymous"); + var response = await deploymentResult.HttpClient.GetAsync("/AuthenticationAnonymous"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("Anonymous?True", responseText); - response = await deploymentResult.RetryingHttpClient.GetAsync("/AuthenticationRestricted"); + response = await deploymentResult.HttpClient.GetAsync("/AuthenticationRestricted"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString()); Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString()); - response = await deploymentResult.RetryingHttpClient.GetAsync("/AuthenticationRestrictedNTLM"); + response = await deploymentResult.HttpClient.GetAsync("/AuthenticationRestrictedNTLM"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString()); // Note we can't restrict a challenge to a specific auth type, the native auth modules always add themselves. Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString()); - response = await deploymentResult.RetryingHttpClient.GetAsync("/AuthenticationForbidden"); + response = await deploymentResult.HttpClient.GetAsync("/AuthenticationForbidden"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); diff --git a/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs b/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs index 1e397731e7..d9dbcd2b6e 100644 --- a/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/ShutdownTests.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests parameters.GracefulShutdown = true; var result = await DeployAsync(parameters); - var response = await result.RetryingHttpClient.GetAsync("/HelloWorld"); + var response = await result.HttpClient.GetAsync("/HelloWorld"); StopServer(); Assert.True(result.HostProcess.ExitCode == 0); } @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var parameters = _fixture.GetBaseDeploymentParameters(publish: true); var result = await DeployAsync(parameters); - var response = await result.RetryingHttpClient.GetAsync("/HelloWorld"); + var response = await result.HttpClient.GetAsync("/HelloWorld"); StopServer(); Assert.True(result.HostProcess.ExitCode == 1); } diff --git a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs index 218cb4b174..89c17d8492 100644 --- a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("HelloWorld"); + var response = await deploymentResult.HttpClient.GetAsync("HelloWorld"); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("HelloWorld"); + var response = await deploymentResult.HttpClient.GetAsync("HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("/HelloWorld"); + var response = await deploymentResult.HttpClient.GetAsync("/HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); @@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("HelloWorld"); + var response = await deploymentResult.HttpClient.GetAsync("HelloWorld"); Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs b/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs index 7ad5d9c9f6..fa859d614a 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/GlobalVersionTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync(_helloWorldRequest); + var response = await deploymentResult.HttpClient.GetAsync(_helloWorldRequest); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); } @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync(_helloWorldRequest); + var response = await deploymentResult.HttpClient.GetAsync(_helloWorldRequest); Assert.False(response.IsSuccessStatusCode); } @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var newANCMPath = GetANCMRequestHandlerPath(deploymentResult, version); Directory.Move(originalANCMPath, newANCMPath); - var response = await deploymentResult.RetryingHttpClient.GetAsync(_helloWorldRequest); + var response = await deploymentResult.HttpClient.GetAsync(_helloWorldRequest); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); AssertLoadedVersion(version); @@ -101,8 +101,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests CopyDirectory(originalANCMPath, newANCMPath); - deploymentResult.RetryingHttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); - var response = await deploymentResult.RetryingHttpClient.GetAsync("CheckRequestHandlerVersion"); + deploymentResult.HttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); + var response = await deploymentResult.HttpClient.GetAsync("CheckRequestHandlerVersion"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); @@ -120,8 +120,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var originalANCMPath = GetANCMRequestHandlerPath(deploymentResult, _handlerVersion20); - deploymentResult.RetryingHttpClient.DefaultRequestHeaders.Add("ANCMRHPath", originalANCMPath); - var response = await deploymentResult.RetryingHttpClient.GetAsync("CheckRequestHandlerVersion"); + deploymentResult.HttpClient.DefaultRequestHeaders.Add("ANCMRHPath", originalANCMPath); + var response = await deploymentResult.HttpClient.GetAsync("CheckRequestHandlerVersion"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); @@ -136,8 +136,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests CopyDirectory(originalANCMPath, newANCMPath); - deploymentResult.RetryingHttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); - response = await deploymentResult.RetryingHttpClient.GetAsync("CheckRequestHandlerVersion"); + deploymentResult.HttpClient.DefaultRequestHeaders.Add("ANCMRHPath", newANCMPath); + response = await deploymentResult.HttpClient.GetAsync("CheckRequestHandlerVersion"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs b/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs index 91c5291b0a..5735393c57 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/HttpsTest.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { ServerCertificateCustomValidationCallback = (a, b, c, d) => true }; - var client = deploymentResult.CreateRetryClient(handler); + var client = deploymentResult.CreateClient(handler); var response = await client.GetAsync("HttpsHelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Scheme:https; Original:http", responseText); @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests handler.ClientCertificates.Add(clientCert); } - var client = deploymentResult.CreateRetryClient(handler); + var client = deploymentResult.CreateClient(handler); // Request to base address and check if various parts of the body are rendered & measure the cold startup time. var response = await client.GetAsync("checkclientcert"); diff --git a/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs b/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs index b67b3b103a..49365998a0 100644 --- a/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs +++ b/test/IISExpress.FunctionalTests/OutOfProcess/NtlmAuthentationTest.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests deploymentParameters.AddWindowsAuthToServerConfig(); var result = await DeployAsync(deploymentParameters); - var response = await result.RetryingHttpClient.GetAsync("/HelloWorld"); + var response = await result.HttpClient.GetAsync("/HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); diff --git a/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs b/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs index 492ae8db87..62d07c5fd9 100644 --- a/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs +++ b/test/IISExpress.FunctionalTests/UpgradeFeatureDetectionTests.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); - var response = await deploymentResult.RetryingHttpClient.GetAsync("UpgradeFeatureDetection"); + var response = await deploymentResult.HttpClient.GetAsync("UpgradeFeatureDetection"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(expected, responseText); }