From 98e35cc6da204c9f07b10606aa1a86f2f2592e37 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Thu, 8 Sep 2016 09:58:10 -0700 Subject: [PATCH] Add retry to ApplicationDeployer delete --- .../Common/RetryHelper.cs | 22 +++++++++++++++++++ .../Deployers/ApplicationDeployer.cs | 14 +++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/RetryHelper.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/RetryHelper.cs index 3e0680ac9b..bc5f5d853e 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/RetryHelper.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/RetryHelper.cs @@ -72,5 +72,27 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting logger.LogInformation("Failed to connect, retry limit exceeded."); throw new OperationCanceledException("Failed to connect, retry limit exceeded."); } + + public static void RetryOperation( + Action retryBlock, + Action exceptionBlock, + int retryCount = 3, + int retryDelayMilliseconds = 0) + { + for (var retry = 0; retry < retryCount; ++retry) + { + try + { + retryBlock(); + break; + } + catch (Exception exception) + { + exceptionBlock(exception); + } + + Thread.Sleep(retryDelayMilliseconds); + } + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs index ac0f43ec58..891ac56e96 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/ApplicationDeployer.cs @@ -90,15 +90,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting } else { - try - { - // We've originally published the application in a temp folder. We need to delete it. - Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true); - } - catch (Exception exception) - { - Logger.LogWarning($"Failed to delete directory : {exception.Message}"); - } + RetryHelper.RetryOperation( + () => Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true), + e => Logger.LogWarning($"Failed to delete directory : {e.Message}"), + retryCount: 3, + retryDelayMilliseconds: 100); } }