Skip to content

Commit

Permalink
Merge pull request #1766 from rabbitmq/lukebakken/misc
Browse files Browse the repository at this point in the history
Misc items
  • Loading branch information
lukebakken authored Jan 13, 2025
2 parents fc8c626 + aa5b3d7 commit 662ace3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
15 changes: 14 additions & 1 deletion projects/RabbitMQ.Client/Impl/AutorecoveringChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,23 @@ await _connection.DeleteRecordedChannelAsync(this,
public override string ToString()
=> InnerChannel.ToString();

public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
public void Dispose()
{
if (_disposed)
{
return;
}

DisposeAsync().AsTask().GetAwaiter().GetResult();
}

public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

if (IsDisposing)
{
return;
Expand Down
15 changes: 14 additions & 1 deletion projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,23 @@ await RecordChannelAsync(autorecoveringChannel, channelsSemaphoreHeld: false, ca
return autorecoveringChannel;
}

public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
public void Dispose()
{
if (_disposed)
{
return;
}

DisposeAsync().AsTask().GetAwaiter().GetResult();
}

public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

if (IsDisposing)
{
return;
Expand Down
18 changes: 17 additions & 1 deletion projects/RabbitMQ.Client/Impl/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ void IDisposable.Dispose()

protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}

if (IsDisposing)
{
return;
Expand Down Expand Up @@ -559,6 +564,11 @@ protected virtual void Dispose(bool disposing)

public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

await DisposeAsyncCore()
.ConfigureAwait(false);

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

protected virtual async ValueTask DisposeAsyncCore()
{
if (_disposed)
{
return;
}

if (IsDisposing)
{
return;
Expand All @@ -576,7 +591,8 @@ protected virtual async ValueTask DisposeAsyncCore()
{
if (IsOpen)
{
await this.AbortAsync().ConfigureAwait(false);
await this.AbortAsync()
.ConfigureAwait(false);
}

if (_serverOriginatedChannelCloseTcs is not null)
Expand Down
15 changes: 14 additions & 1 deletion projects/RabbitMQ.Client/Impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,23 @@ internal ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellatio
return _frameHandler.WriteAsync(frames, cancellationToken);
}

public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
public void Dispose()
{
if (_disposed)
{
return;
}

DisposeAsync().AsTask().GetAwaiter().GetResult();
}

public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

if (IsDisposing)
{
return;
Expand Down
4 changes: 2 additions & 2 deletions projects/Test/Integration/TestQueueDeclare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public async Task TestPassiveQueueDeclareException_GH1749()
{
await _channel.QueueDeclarePassiveAsync(q);
}
catch (Exception ex)
catch (Exception)
{
_output.WriteLine("{0} ex: {1}", _testDisplayName, ex);
// _output.WriteLine("{0} ex: {1}", _testDisplayName, ex);
await _channel.DisposeAsync();
_channel = null;
}
Expand Down
19 changes: 15 additions & 4 deletions projects/Test/Integration/TestToxiproxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,25 @@ public override Task InitializeAsync()
Assert.Null(_conn);
Assert.Null(_channel);

_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
_proxyPort = ToxiproxyManager.ProxyPort;
return _toxiproxyManager.InitializeAsync();
if (AreToxiproxyTestsEnabled)
{
_toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows);
_proxyPort = ToxiproxyManager.ProxyPort;
return _toxiproxyManager.InitializeAsync();
}
else
{
return Task.CompletedTask;
}
}

public override async Task DisposeAsync()
{
await _toxiproxyManager.DisposeAsync();
if (AreToxiproxyTestsEnabled)
{
await _toxiproxyManager.DisposeAsync();
}

await base.DisposeAsync();
}

Expand Down

0 comments on commit 662ace3

Please sign in to comment.