Defensively stop redis container before starting (#1356)

This commit is contained in:
BrennanConroy 2018-01-25 21:15:15 -08:00 committed by GitHub
parent 33d391349a
commit 1cc4098d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -57,6 +57,9 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
{
logger.LogInformation("Starting docker container");
// stop container if there is one, could be from a previous test run, ignore failures
RunProcess(_path, $"stop {_dockerContainerName}", logger, TimeSpan.FromSeconds(5), out var output);
// create and run docker container, remove automatically when stopped, map 6379 from the container to 6379 localhost
// use static name 'redisTestContainer' so if the container doesn't get removed we don't keep adding more
// use redis base docker image
@ -76,13 +79,13 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
public int RunCommand(string commandAndArguments, ILogger logger, out string output)
{
return RunProcess(_path, commandAndArguments, logger, TimeSpan.FromSeconds(5), out output);
}
}
private static void RunProcessAndThrowIfFailed(string fileName, string arguments, ILogger logger, TimeSpan timeout)
{
var exitCode = RunProcess(fileName, arguments, logger, timeout, out var output);
if(exitCode != 0)
if (exitCode != 0)
{
throw new Exception($"Command '{fileName} {arguments}' failed with exit code '{exitCode}'. Output:{Environment.NewLine}{output}");
}