Add locked app_oflline file test and remove retrying client (#1178)

* Add locked app_oflline file test and remove retrying client

* Write bytes to file
This commit is contained in:
Pavel Krymets 2018-08-09 09:21:02 -07:00 committed by GitHub
parent 8cf39d3592
commit d6f410bf42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 58 additions and 47 deletions

View File

@ -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; }
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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);

View File

@ -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);
}