Skip to content

Commit

Permalink
* Add retries to starting a Toxiproxy instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Dec 9, 2024
1 parent 5f83f0f commit 5574aac
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions projects/Test/Integration/ToxiproxyManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -69,7 +70,8 @@ public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindo

public async Task InitializeAsync()
{
_proxy.Name = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}-{Util.GenerateShortUuid()}";
string proxyName = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}-{Util.GenerateShortUuid()}";
_proxy.Name = proxyName;

try
{
Expand All @@ -79,7 +81,28 @@ public async Task InitializeAsync()
{
}

await _proxyClient.AddAsync(_proxy);
ushort retryCount = 5;
do
{
try
{
await _proxyClient.AddAsync(_proxy);
}
catch (Exception ex)
{
if (retryCount == 0)
{
throw;
}
else
{
string now = DateTime.Now.ToString("o", CultureInfo.InvariantCulture);
Console.Error.WriteLine("{0} [ERROR] error initializing proxy '{1}': {2}", now, proxyName, ex);
}
}
--retryCount;
await Task.Delay(TimeSpan.FromSeconds(1));
} while (retryCount >= 0);
}

public Task<T> AddToxicAsync<T>(T toxic) where T : ToxicBase
Expand Down

0 comments on commit 5574aac

Please sign in to comment.