SignalR 739 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. commit a03b8f85a8b2583db646c5945825a21533b585c8
  2. Author: BrennanConroy <[email protected]>
  3. Date: Wed Nov 7 08:48:49 2018 -0800
  4. Add docker retry to stackexchange redis tests (#3270)
  5. diff --git a/test/Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests/Docker.cs b/test/Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests/Docker.cs
  6. index d8722505c21..cd79c35c775 100644
  7. --- a/test/Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests/Docker.cs
  8. +++ b/test/Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests/Docker.cs
  9. @@ -6,6 +6,7 @@ using System.Collections.Concurrent;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using System.Runtime.InteropServices;
  13. +using System.Threading;
  14. using Microsoft.Extensions.Logging;
  15. using Microsoft.Extensions.Logging.Abstractions;
  16. @@ -70,6 +71,29 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
  17. return null;
  18. }
  19. + private void StartRedis(ILogger logger)
  20. + {
  21. + try
  22. + {
  23. + Run();
  24. + }
  25. + catch (Exception ex)
  26. + {
  27. + logger.LogError(ex, "Error starting redis docker container, retrying.");
  28. + Thread.Sleep(1000);
  29. + Run();
  30. + }
  31. +
  32. + void Run()
  33. + {
  34. + // create and run docker container, remove automatically when stopped, map 6379 from the container to 6379 localhost
  35. + // use static name 'redisTestContainer' so if the container doesn't get removed we don't keep adding more
  36. + // use redis base docker image
  37. + // 30 second timeout to allow redis image to be downloaded, should be a rare occurrence, only happening when a new version is released
  38. + RunProcessAndThrowIfFailed(_path, $"run --rm -p 6379:6379 --name {_dockerContainerName} -d redis", "redis", logger, TimeSpan.FromSeconds(30));
  39. + }
  40. + }
  41. +
  42. public void Start(ILogger logger)
  43. {
  44. logger.LogInformation("Starting docker container");
  45. @@ -78,11 +102,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
  46. RunProcessAndWait(_path, $"stop {_dockerMonitorContainerName}", "docker stop", logger, TimeSpan.FromSeconds(15), out var _);
  47. RunProcessAndWait(_path, $"stop {_dockerContainerName}", "docker stop", logger, TimeSpan.FromSeconds(15), out var output);
  48. - // create and run docker container, remove automatically when stopped, map 6379 from the container to 6379 localhost
  49. - // use static name 'redisTestContainer' so if the container doesn't get removed we don't keep adding more
  50. - // use redis base docker image
  51. - // 20 second timeout to allow redis image to be downloaded, should be a rare occurrence, only happening when a new version is released
  52. - RunProcessAndThrowIfFailed(_path, $"run --rm -p 6379:6379 --name {_dockerContainerName} -d redis", "redis", logger, TimeSpan.FromSeconds(20));
  53. + StartRedis(logger);
  54. // 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
  55. // outside the current container requires linking the networks (difficult to automate) or using the IP:Port combo