Skip to content

Commit aa5b3d7

Browse files
committed
Misc items
* Only setup / dispose ToxiproxyManager when those tests are enabled. * Comment-out test output. * Additional `_disposed` checks. * Additional `_disposed` checks in `AutorecoveringChannel`. * Additional `_disposed` checks in `Connection`. * Add `_disposed` check in `AutorecoveringConnection` * Cosmetic `ConfigureAwait(false)`
1 parent fc8c626 commit aa5b3d7

File tree

6 files changed

+76
-10
lines changed

6 files changed

+76
-10
lines changed

projects/RabbitMQ.Client/Impl/AutorecoveringChannel.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,23 @@ await _connection.DeleteRecordedChannelAsync(this,
254254
public override string ToString()
255255
=> InnerChannel.ToString();
256256

257-
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
257+
public void Dispose()
258+
{
259+
if (_disposed)
260+
{
261+
return;
262+
}
263+
264+
DisposeAsync().AsTask().GetAwaiter().GetResult();
265+
}
258266

259267
public async ValueTask DisposeAsync()
260268
{
269+
if (_disposed)
270+
{
271+
return;
272+
}
273+
261274
if (IsDisposing)
262275
{
263276
return;

projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,23 @@ await RecordChannelAsync(autorecoveringChannel, channelsSemaphoreHeld: false, ca
270270
return autorecoveringChannel;
271271
}
272272

273-
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
273+
public void Dispose()
274+
{
275+
if (_disposed)
276+
{
277+
return;
278+
}
279+
280+
DisposeAsync().AsTask().GetAwaiter().GetResult();
281+
}
274282

275283
public async ValueTask DisposeAsync()
276284
{
285+
if (_disposed)
286+
{
287+
return;
288+
}
289+
277290
if (IsDisposing)
278291
{
279292
return;

projects/RabbitMQ.Client/Impl/Channel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ void IDisposable.Dispose()
529529

530530
protected virtual void Dispose(bool disposing)
531531
{
532+
if (_disposed)
533+
{
534+
return;
535+
}
536+
532537
if (IsDisposing)
533538
{
534539
return;
@@ -559,6 +564,11 @@ protected virtual void Dispose(bool disposing)
559564

560565
public async ValueTask DisposeAsync()
561566
{
567+
if (_disposed)
568+
{
569+
return;
570+
}
571+
562572
await DisposeAsyncCore()
563573
.ConfigureAwait(false);
564574

@@ -567,6 +577,11 @@ await DisposeAsyncCore()
567577

568578
protected virtual async ValueTask DisposeAsyncCore()
569579
{
580+
if (_disposed)
581+
{
582+
return;
583+
}
584+
570585
if (IsDisposing)
571586
{
572587
return;
@@ -576,7 +591,8 @@ protected virtual async ValueTask DisposeAsyncCore()
576591
{
577592
if (IsOpen)
578593
{
579-
await this.AbortAsync().ConfigureAwait(false);
594+
await this.AbortAsync()
595+
.ConfigureAwait(false);
580596
}
581597

582598
if (_serverOriginatedChannelCloseTcs is not null)

projects/RabbitMQ.Client/Impl/Connection.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,23 @@ internal ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellatio
487487
return _frameHandler.WriteAsync(frames, cancellationToken);
488488
}
489489

490-
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
490+
public void Dispose()
491+
{
492+
if (_disposed)
493+
{
494+
return;
495+
}
496+
497+
DisposeAsync().AsTask().GetAwaiter().GetResult();
498+
}
491499

492500
public async ValueTask DisposeAsync()
493501
{
502+
if (_disposed)
503+
{
504+
return;
505+
}
506+
494507
if (IsDisposing)
495508
{
496509
return;

projects/Test/Integration/TestQueueDeclare.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public async Task TestPassiveQueueDeclareException_GH1749()
6565
{
6666
await _channel.QueueDeclarePassiveAsync(q);
6767
}
68-
catch (Exception ex)
68+
catch (Exception)
6969
{
70-
_output.WriteLine("{0} ex: {1}", _testDisplayName, ex);
70+
// _output.WriteLine("{0} ex: {1}", _testDisplayName, ex);
7171
await _channel.DisposeAsync();
7272
_channel = null;
7373
}

projects/Test/Integration/TestToxiproxy.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,25 @@ public override Task InitializeAsync()
6161
Assert.Null(_conn);
6262
Assert.Null(_channel);
6363

64-
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
65-
_proxyPort = ToxiproxyManager.ProxyPort;
66-
return _toxiproxyManager.InitializeAsync();
64+
if (AreToxiproxyTestsEnabled)
65+
{
66+
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
67+
_proxyPort = ToxiproxyManager.ProxyPort;
68+
return _toxiproxyManager.InitializeAsync();
69+
}
70+
else
71+
{
72+
return Task.CompletedTask;
73+
}
6774
}
6875

6976
public override async Task DisposeAsync()
7077
{
71-
await _toxiproxyManager.DisposeAsync();
78+
if (AreToxiproxyTestsEnabled)
79+
{
80+
await _toxiproxyManager.DisposeAsync();
81+
}
82+
7283
await base.DisposeAsync();
7384
}
7485

0 commit comments

Comments
 (0)