private void RemoveAppOffline(string appPath) { RetryHelper.RetryOperation( () => File.Delete(Path.Combine(appPath, "app_offline.htm")), e => Logger.LogError($"Failed to remove app_offline : {e.Message}"), retryCount: 3, retryDelayMilliseconds: RetryDelay.Milliseconds); }
public void Dispose() { RetryHelper.RetryOperation( () => Directory.Delete(Path, true), e => _logger.LogWarning($"Failed to delete directory : {e.Message}"), retryCount: 3, retryDelayMilliseconds: 100); }
private void GetLogsFromFile(string file) { var arr = new string[0]; RetryHelper.RetryOperation(() => arr = File.ReadAllLines(Path.Combine(DeploymentParameters.PublishedApplicationRootPath, file)), (ex) => Logger.LogWarning("Could not read log file"), 5, 200); Logger.LogInformation($"Found debug log file: {file}"); foreach (var line in arr) { Logger.LogInformation(line); } }
public async Task CheckStdoutLogging(string path) { var deploymentParameters = Helpers.GetBaseDeploymentParameters(); deploymentParameters.PublishApplicationBeforeDeployment = true; deploymentParameters.PreservePublishedApplicationForDebugging = true; // workaround for keeping var deploymentResult = await DeployAsync(deploymentParameters); try { Helpers.ModifyAspNetCoreSectionInWebConfig(deploymentResult, "stdoutLogEnabled", "true"); Helpers.ModifyAspNetCoreSectionInWebConfig(deploymentResult, "stdoutLogFile", @".\logs\stdout"); var response = await deploymentResult.RetryingHttpClient.GetAsync(path); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); StopServer(); var folderPath = Path.Combine(deploymentResult.DeploymentResult.ContentRoot, @"logs"); var fileInDirectory = Directory.GetFiles(folderPath).Single(); Assert.NotNull(fileInDirectory); string contents = null; // RetryOperation doesn't support async lambdas, call synchronous ReadAllText. RetryHelper.RetryOperation( () => contents = File.ReadAllText(fileInDirectory), e => Logger.LogError($"Failed to read file: {e.Message}"), retryCount: 10, retryDelayMilliseconds: 100); Assert.NotNull(contents); Assert.Contains("TEST MESSAGE", contents); } finally { RetryHelper.RetryOperation( () => Directory.Delete(deploymentParameters.PublishedApplicationRootPath, true), e => Logger.LogWarning($"Failed to delete directory : {e.Message}"), retryCount: 3, retryDelayMilliseconds: 100); } }
private async Task AppOfflineAddAndRemovedStress(HostingModel hostingModel) { var deploymentResult = await AssertStarts(hostingModel); var load = Helpers.StressLoad(deploymentResult.HttpClient, "/HelloWorld", response => { var statusCode = (int)response.StatusCode; // Test failure involves the stress load receiving a 400 Bad Request. // We think it is due to IIS returning the 400 itself, but need to confirm the hypothesis. if (statusCode == 400) { Logger.LogError($"Status code was a bad request. Content: {response.Content.ReadAsStringAsync().GetAwaiter().GetResult()}"); } Assert.True(statusCode == 200 || statusCode == 503, "Status code was " + statusCode); }); for (int i = 0; i < 5; i++) { // AddAppOffline might fail if app_offline is being read by ANCM and deleted at the same time RetryHelper.RetryOperation( () => AddAppOffline(deploymentResult.ContentRoot), e => Logger.LogError($"Failed to create app_offline : {e.Message}"), retryCount: 3, retryDelayMilliseconds: RetryDelay.Milliseconds); RemoveAppOffline(deploymentResult.ContentRoot); } try { await load; } catch (HttpRequestException ex) when(ex.InnerException is IOException | ex.InnerException is SocketException) { // IOException in InProcess is fine, just means process stopped if (hostingModel != HostingModel.InProcess) { throw; } } }
public async Task CheckStdoutLoggingToFile(string path) { var deploymentParameters = Helpers.GetBaseDeploymentParameters(publish: true); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true")); var pathToLogs = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogFile", Path.Combine(pathToLogs, "std"))); var deploymentResult = await DeployAsync(deploymentParameters); try { await Helpers.AssertStarts(deploymentResult, path); StopServer(); var fileInDirectory = Directory.GetFiles(pathToLogs).Single(); var contents = File.ReadAllText(fileInDirectory); Assert.NotNull(contents); Assert.Contains("TEST MESSAGE", contents); Assert.DoesNotContain(TestSink.Writes, context => context.Message.Contains("TEST MESSAGE")); // TODO we should check that debug logs are restored during graceful shutdown. // The IIS Express deployer doesn't support graceful shutdown. //Assert.Contains(TestSink.Writes, context => context.Message.Contains("Restoring original stdout: ")); } finally { RetryHelper.RetryOperation( () => Directory.Delete(pathToLogs, true), e => Logger.LogWarning($"Failed to delete directory : {e.Message}"), retryCount: 3, retryDelayMilliseconds: 100); } }
public void Dispose() { if (string.IsNullOrEmpty(_storeDir)) { return; } if (Helpers.PreservePublishedApplicationForDebugging) { _logger.LogInformation("Skipping deleting the store as it has been disabled"); } else { _logger.LogInformation($"Deleting the store directory {_storeParentDir}..."); RetryHelper.RetryOperation( () => Directory.Delete(_storeParentDir, recursive: true), e => _logger.LogError($"Failed to delete directory : {e.Message}"), retryCount: 3, retryDelayMilliseconds: 100); } }