Add retry to ApplicationDeployer delete

This commit is contained in:
BrennanConroy 2016-09-08 09:58:10 -07:00
parent 2fe8c27f30
commit 98e35cc6da
2 changed files with 27 additions and 9 deletions

View File

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

View File

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