Skip to content

Commit 5574aac

Browse files
committed
* Add retries to starting a Toxiproxy instance.
1 parent 5f83f0f commit 5574aac

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

projects/Test/Integration/ToxiproxyManager.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Net;
34
using System.Threading;
45
using System.Threading.Tasks;
@@ -69,7 +70,8 @@ public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindo
6970

7071
public async Task InitializeAsync()
7172
{
72-
_proxy.Name = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}-{Util.GenerateShortUuid()}";
73+
string proxyName = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}-{Util.GenerateShortUuid()}";
74+
_proxy.Name = proxyName;
7375

7476
try
7577
{
@@ -79,7 +81,28 @@ public async Task InitializeAsync()
7981
{
8082
}
8183

82-
await _proxyClient.AddAsync(_proxy);
84+
ushort retryCount = 5;
85+
do
86+
{
87+
try
88+
{
89+
await _proxyClient.AddAsync(_proxy);
90+
}
91+
catch (Exception ex)
92+
{
93+
if (retryCount == 0)
94+
{
95+
throw;
96+
}
97+
else
98+
{
99+
string now = DateTime.Now.ToString("o", CultureInfo.InvariantCulture);
100+
Console.Error.WriteLine("{0} [ERROR] error initializing proxy '{1}': {2}", now, proxyName, ex);
101+
}
102+
}
103+
--retryCount;
104+
await Task.Delay(TimeSpan.FromSeconds(1));
105+
} while (retryCount >= 0);
83106
}
84107

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

0 commit comments

Comments
 (0)