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