Skip to content

Commit bd1a4e1

Browse files
committed
* Still trying to track down GHA issues
1 parent accd48c commit bd1a4e1

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

projects/Test/Integration/TestToxiproxy.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ namespace Test.Integration
4646
public class TestToxiproxy : IntegrationFixture
4747
{
4848
private readonly TimeSpan _heartbeatTimeout = TimeSpan.FromSeconds(1);
49+
private ToxiproxyManager _toxiproxyManager;
50+
private int _proxyPort;
4951

5052
public TestToxiproxy(ITestOutputHelper output) : base(output)
5153
{
@@ -59,7 +61,15 @@ public override Task InitializeAsync()
5961
Assert.Null(_conn);
6062
Assert.Null(_channel);
6163

62-
return Task.CompletedTask;
64+
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
65+
_proxyPort = _toxiproxyManager.ProxyPort;
66+
return _toxiproxyManager.InitializeAsync();
67+
}
68+
69+
public override async Task DisposeAsync()
70+
{
71+
await _toxiproxyManager.DisposeAsync();
72+
await base.DisposeAsync();
6373
}
6474

6575
[SkippableFact]
@@ -68,11 +78,8 @@ public async Task TestCloseConnection()
6878
{
6979
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
7080

71-
using var pm = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
72-
await pm.InitializeAsync();
73-
7481
ConnectionFactory cf = CreateConnectionFactory();
75-
cf.Port = pm.ProxyPort;
82+
cf.Port = _proxyPort;
7683
cf.AutomaticRecoveryEnabled = true;
7784
cf.NetworkRecoveryInterval = TimeSpan.FromSeconds(1);
7885
cf.RequestedHeartbeat = TimeSpan.FromSeconds(1);
@@ -172,11 +179,11 @@ async Task PublishLoop()
172179

173180
Assert.True(await messagePublishedTcs.Task);
174181

175-
Task disableProxyTask = pm.DisableAsync();
182+
Task disableProxyTask = _toxiproxyManager.DisableAsync();
176183

177184
await Task.WhenAll(disableProxyTask, connectionShutdownTcs.Task);
178185

179-
Task enableProxyTask = pm.EnableAsync();
186+
Task enableProxyTask = _toxiproxyManager.EnableAsync();
180187

181188
Task whenAllTask = Task.WhenAll(enableProxyTask, recoverySucceededTcs.Task);
182189
await whenAllTask.WaitAsync(TimeSpan.FromSeconds(15));
@@ -193,11 +200,8 @@ public async Task TestThatStoppedSocketResultsInHeartbeatTimeout()
193200
{
194201
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
195202

196-
using var pm = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
197-
await pm.InitializeAsync();
198-
199203
ConnectionFactory cf = CreateConnectionFactory();
200-
cf.Port = pm.ProxyPort;
204+
cf.Port = _proxyPort;
201205
cf.RequestedHeartbeat = _heartbeatTimeout;
202206
cf.AutomaticRecoveryEnabled = false;
203207

@@ -229,7 +233,7 @@ public async Task TestThatStoppedSocketResultsInHeartbeatTimeout()
229233
timeoutToxic.Attributes.Timeout = 0;
230234
timeoutToxic.Toxicity = 1.0;
231235

232-
Task<TimeoutToxic> addToxicTask = pm.AddToxicAsync(timeoutToxic);
236+
Task<TimeoutToxic> addToxicTask = _toxiproxyManager.AddToxicAsync(timeoutToxic);
233237

234238
await Assert.ThrowsAsync<AlreadyClosedException>(() =>
235239
{
@@ -243,11 +247,8 @@ public async Task TestTcpReset_GH1464()
243247
{
244248
Skip.IfNot(AreToxiproxyTestsEnabled, "RABBITMQ_TOXIPROXY_TESTS is not set, skipping test");
245249

246-
using var pm = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
247-
await pm.InitializeAsync();
248-
249250
ConnectionFactory cf = CreateConnectionFactory();
250-
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), pm.ProxyPort);
251+
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), _proxyPort);
251252
cf.RequestedHeartbeat = TimeSpan.FromSeconds(5);
252253
cf.AutomaticRecoveryEnabled = true;
253254

@@ -283,11 +284,11 @@ public async Task TestTcpReset_GH1464()
283284
resetPeerToxic.Attributes.Timeout = 500;
284285
resetPeerToxic.Toxicity = 1.0;
285286

286-
Task<ResetPeerToxic> addToxicTask = pm.AddToxicAsync(resetPeerToxic);
287+
Task<ResetPeerToxic> addToxicTask = _toxiproxyManager.AddToxicAsync(resetPeerToxic);
287288

288289
await Task.WhenAll(addToxicTask, connectionShutdownTcs.Task);
289290

290-
await pm.RemoveToxicAsync(toxicName);
291+
await _toxiproxyManager.RemoveToxicAsync(toxicName);
291292

292293
await recoveryTask;
293294
}
@@ -302,11 +303,8 @@ public async Task TestPublisherConfirmationThrottling()
302303
const int MaxOutstandingConfirms = 8;
303304
const int BatchSize = MaxOutstandingConfirms * 2;
304305

305-
using var pm = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
306-
await pm.InitializeAsync();
307-
308306
ConnectionFactory cf = CreateConnectionFactory();
309-
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), pm.ProxyPort);
307+
cf.Endpoint = new AmqpTcpEndpoint(IPAddress.Loopback.ToString(), _proxyPort);
310308
cf.RequestedHeartbeat = TimeSpan.FromSeconds(5);
311309
cf.AutomaticRecoveryEnabled = true;
312310

@@ -371,7 +369,7 @@ public async Task TestPublisherConfirmationThrottling()
371369

372370
await Task.Delay(TimeSpan.FromSeconds(1));
373371

374-
Task<BandwidthToxic> addToxicTask = pm.AddToxicAsync(bandwidthToxic);
372+
Task<BandwidthToxic> addToxicTask = _toxiproxyManager.AddToxicAsync(bandwidthToxic);
375373

376374
while (true)
377375
{
@@ -387,7 +385,7 @@ public async Task TestPublisherConfirmationThrottling()
387385
}
388386

389387
await addToxicTask.WaitAsync(WaitSpan);
390-
await pm.RemoveToxicAsync(toxicName).WaitAsync(WaitSpan);
388+
await _toxiproxyManager.RemoveToxicAsync(toxicName).WaitAsync(WaitSpan);
391389

392390
await messagesPublishedTcs.Task.WaitAsync(WaitSpan);
393391
await publishTask.WaitAsync(WaitSpan);

projects/Test/Integration/ToxiproxyManager.cs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Integration
1111
{
12-
public class ToxiproxyManager : IDisposable
12+
public class ToxiproxyManager : IAsyncDisposable
1313
{
1414
private const string ProxyNamePrefix = "rmq";
1515
private const ushort ProxyPortStart = 55669;
@@ -21,7 +21,7 @@ public class ToxiproxyManager : IDisposable
2121
private readonly Client _proxyClient;
2222
private readonly Proxy _proxy;
2323

24-
private bool _disposedValue;
24+
private bool _disposedValue = false;
2525

2626
public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindows)
2727
{
@@ -115,30 +115,24 @@ public Task DisableAsync()
115115
return _proxyClient.UpdateAsync(_proxy);
116116
}
117117

118-
public void Dispose()
119-
{
120-
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
121-
Dispose(disposing: true);
122-
GC.SuppressFinalize(this);
123-
}
124-
125-
protected virtual void Dispose(bool disposing)
118+
public async ValueTask DisposeAsync()
126119
{
127120
if (!_disposedValue)
128121
{
129-
if (disposing)
122+
try
130123
{
131-
try
132-
{
133-
_proxyClient.DeleteAsync(_proxy).GetAwaiter().GetResult();
134-
_proxyConnection.Dispose();
135-
}
136-
catch
137-
{
138-
}
124+
await _proxyClient.DeleteAsync(_proxy);
125+
_proxyConnection.Dispose();
126+
}
127+
catch (Exception ex)
128+
{
129+
string now = DateTime.Now.ToString("o", CultureInfo.InvariantCulture);
130+
Console.Error.WriteLine("{0} [ERROR] error disposing proxy '{1}': {2}", now, _proxy.Name, ex);
131+
}
132+
finally
133+
{
134+
_disposedValue = true;
139135
}
140-
141-
_disposedValue = true;
142136
}
143137
}
144138
}

0 commit comments

Comments
 (0)