Skip to content

Commit 56f78b4

Browse files
Retry redis docker (#3265)
1 parent 7ae4cb0 commit 56f78b4

File tree

1 file changed

+25
-5
lines changed
  • test/Microsoft.AspNetCore.SignalR.Redis.Tests

1 file changed

+25
-5
lines changed

test/Microsoft.AspNetCore.SignalR.Redis.Tests/Docker.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.IO;
88
using System.Runtime.InteropServices;
9+
using System.Threading;
910
using Microsoft.Extensions.Logging;
1011
using Microsoft.Extensions.Logging.Abstractions;
1112

@@ -70,6 +71,29 @@ private static string GetDockerLocation()
7071
return null;
7172
}
7273

74+
private void StartRedis(ILogger logger)
75+
{
76+
try
77+
{
78+
Run();
79+
}
80+
catch (Exception ex)
81+
{
82+
logger.LogError(ex, "Error starting redis docker container, retrying.");
83+
Thread.Sleep(1000);
84+
Run();
85+
}
86+
87+
void Run()
88+
{
89+
// create and run docker container, remove automatically when stopped, map 6379 from the container to 6379 localhost
90+
// use static name 'redisTestContainer' so if the container doesn't get removed we don't keep adding more
91+
// use redis base docker image
92+
// 30 second timeout to allow redis image to be downloaded, should be a rare occurrence, only happening when a new version is released
93+
RunProcessAndThrowIfFailed(_path, $"run --rm -p 6380:6379 --name {_dockerContainerName} -d redis", "redis", logger, TimeSpan.FromSeconds(30));
94+
}
95+
}
96+
7397
public void Start(ILogger logger)
7498
{
7599
logger.LogInformation("Starting docker container");
@@ -78,11 +102,7 @@ public void Start(ILogger logger)
78102
RunProcessAndWait(_path, $"stop {_dockerMonitorContainerName}", "docker stop", logger, TimeSpan.FromSeconds(15), out var _);
79103
RunProcessAndWait(_path, $"stop {_dockerContainerName}", "docker stop", logger, TimeSpan.FromSeconds(15), out var output);
80104

81-
// create and run docker container, remove automatically when stopped, map 6379 from the container to 6379 localhost
82-
// use static name 'redisTestContainer' so if the container doesn't get removed we don't keep adding more
83-
// use redis base docker image
84-
// 20 second timeout to allow redis image to be downloaded, should be a rare occurrence, only happening when a new version is released
85-
RunProcessAndThrowIfFailed(_path, $"run --rm -p 6380:6379 --name {_dockerContainerName} -d redis", "redis", logger, TimeSpan.FromSeconds(20));
105+
StartRedis(logger);
86106

87107
// inspect the redis docker image and extract the IPAddress. Necessary when running tests from inside a docker container, spinning up a new docker container for redis
88108
// outside the current container requires linking the networks (difficult to automate) or using the IP:Port combo

0 commit comments

Comments
 (0)