Skip to content

Commit

Permalink
Merge branch 'main' into feat/add_activity_on_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
aygalinc authored Dec 9, 2024
2 parents 06f2d1b + a8dc8ce commit dc89271
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
path: |
~/.nuget/packages
~/AppData/Local/NuGet/v3-cache
key: ${{ runner.os }}-v1-nuget-${{ hashFiles('**/*.csproj') }}
key: ${{ runner.os }}-v2-nuget-${{ hashFiles('**/*.csproj','projects/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-v1-nuget-
${{ runner.os }}-v2-nuget-
- name: Build (Debug)
run: dotnet build ${{ github.workspace }}\Build.csproj
- name: Verify
Expand Down Expand Up @@ -142,9 +142,9 @@ jobs:
path: |
~/.nuget/packages
~/.local/share/NuGet/v3-cache
key: ${{ runner.os }}-v1-nuget-${{ hashFiles('**/*.csproj') }}
key: ${{ runner.os }}-v2-nuget-${{ hashFiles('**/*.csproj','projects/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-v1-nuget-
${{ runner.os }}-v2-nuget-
- name: Build (Debug)
run: dotnet build ${{ github.workspace }}/Build.csproj
- name: Verify
Expand Down
6 changes: 2 additions & 4 deletions projects/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
-->
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.Threading.RateLimiting" Version="8.0.0" />
<PackageVersion Include="WireMock.Net" Version="1.5.62" />
<PackageVersion Include="xunit" Version="2.9.0" />
Expand All @@ -33,13 +35,9 @@
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework)=='net472'">
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CredentialsRefresherEventSource : EventSource
public void Stopped(string name) => WriteEvent(2, "Stopped", name);

[Event(3)]
#if NET6_0_OR_GREATER
#if NET
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
#endif
public void RefreshedCredentials(string name) => WriteEvent(3, "RefreshedCredentials", name);
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/DefaultEndpointResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
public class DefaultEndpointResolver : IEndpointResolver
{
#if !NET6_0_OR_GREATER
#if !NET
private readonly Random s_rnd = new Random();
#endif
private readonly List<AmqpTcpEndpoint> _endpoints;
Expand All @@ -49,7 +49,7 @@ public DefaultEndpointResolver(IEnumerable<AmqpTcpEndpoint> tcpEndpoints)

public IEnumerable<AmqpTcpEndpoint> All()
{
#if NET6_0_OR_GREATER
#if NET
return _endpoints.OrderBy(item => Random.Shared.Next());
#else
return _endpoints.OrderBy(item => s_rnd.Next());
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/Impl/AsyncManualResetEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();

CancellationTokenRegistration tokenRegistration =
#if NET6_0_OR_GREATER
#if NET
cancellationToken.UnsafeRegister(
static state =>
{
Expand All @@ -87,7 +87,7 @@ public async ValueTask WaitAsync(CancellationToken cancellationToken)
}
finally
{
#if NET6_0_OR_GREATER
#if NET
await tokenRegistration.DisposeAsync()
.ConfigureAwait(false);
#else
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/AsyncRpcContinuations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AsyncRpcContinuation(TimeSpan continuationTimeout, CancellationToken canc
*/
_continuationTimeoutCancellationTokenSource = new CancellationTokenSource(continuationTimeout);

#if NET6_0_OR_GREATER
#if NET
_continuationTimeoutCancellationTokenRegistration = _continuationTimeoutCancellationTokenSource.Token.UnsafeRegister((object? state) =>
{
var tcs = (TaskCompletionSource<T>)state!;
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/Impl/Connection.Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken)
{
var connectionStartCell = new TaskCompletionSource<ConnectionStartDetails?>(TaskCreationOptions.RunContinuationsAsynchronously);

#if NET6_0_OR_GREATER
#if NET
using CancellationTokenRegistration ctr = cancellationToken.UnsafeRegister((object? state) =>
{
if (state != null)
Expand Down Expand Up @@ -197,7 +197,7 @@ private IAuthMechanismFactory GetAuthMechanismFactory(string supportedMechanismN
// Our list is in order of preference, the server one is not.
foreach (IAuthMechanismFactory factory in _config.AuthMechanisms)
{
#if NET6_0_OR_GREATER
#if NET
if (supportedMechanismNames.Contains(factory.Name, StringComparison.OrdinalIgnoreCase))
#else
if (supportedMechanismNames.IndexOf(factory.Name, StringComparison.OrdinalIgnoreCase) >= 0)
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/RecordedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override bool Equals(object? obj)

public override int GetHashCode()
{
#if NET6_0_OR_GREATER
#if NET
return HashCode.Combine(_isQueueBinding, _destination, _source, _routingKey, _arguments);
#else
unchecked
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/SocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task<ITcpClient> OpenAsync(AmqpTcpEndpoint amqpTcpEndpoint,
{
IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(
amqpTcpEndpoint.HostName
#if NET6_0_OR_GREATER
#if NET
, cancellationToken
#endif
).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/SslHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static async Task<Stream> TcpUpgradeAsync(Stream tcpStream, SslOption opt

Task TryAuthenticating(SslOption opts)
{
#if NET6_0_OR_GREATER
#if NET
X509RevocationMode certificateRevocationCheckMode = X509RevocationMode.NoCheck;
if (opts.CheckCertificateRevocation)
{
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/WireFormatting.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static int ReadShortstr(ReadOnlySpan<byte> span, out string value)
// equals span.Length >= byteCount + 1
if (span.Length > byteCount)
{
#if NETCOREAPP
#if NET
value = UTF8.GetString(span.Slice(1, byteCount));
#else
unsafe
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/Impl/WireFormatting.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static int GetArrayByteCount(IList? val)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NETCOREAPP
#if NET
public static int GetByteCount(ReadOnlySpan<char> val) => val.IsEmpty ? 0 : UTF8.GetByteCount(val);
#else
public static int GetByteCount(string val) => string.IsNullOrEmpty(val) ? 0 : UTF8.GetByteCount(val);
Expand Down
6 changes: 3 additions & 3 deletions projects/RabbitMQ.Client/Logging/RabbitMqClientEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
{
public static readonly RabbitMqClientEventSource Log = new RabbitMqClientEventSource();

#if NET6_0_OR_GREATER
#if NET
private readonly PollingCounter _connectionOpenedCounter;
private readonly PollingCounter _openConnectionCounter;
private readonly PollingCounter _channelOpenedCounter;
Expand All @@ -54,7 +54,7 @@ internal sealed partial class RabbitMqClientEventSource : EventSource
public RabbitMqClientEventSource()
: base("rabbitmq-client")
{
#if NET6_0_OR_GREATER
#if NET
_connectionOpenedCounter = new PollingCounter("total-connections-opened", this, () => s_connectionsOpened)
{
DisplayName = "Total connections opened"
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Warn(string message)
}
}

#if NET6_0_OR_GREATER
#if NET
[Event(3, Keywords = Keywords.Log, Level = EventLevel.Error)]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The properties are preserved with the DynamicallyAccessedMembers attribute.")]
public void Error(string message, RabbitMqExceptionDetail ex)
Expand Down
8 changes: 4 additions & 4 deletions projects/RabbitMQ.Client/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RabbitMQ.Client
{
internal static class TaskExtensions
{
#if NET6_0_OR_GREATER
#if NET
public static bool IsCompletedSuccessfully(this Task task)
{
return task.IsCompletedSuccessfully;
Expand All @@ -49,7 +49,7 @@ public static bool IsCompletedSuccessfully(this Task task)
}
#endif

#if !NET6_0_OR_GREATER
#if !NET
private static readonly TaskContinuationOptions s_tco = TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously;
private static void IgnoreTaskContinuation(Task t, object s) => t.Exception.Handle(e => true);

Expand Down Expand Up @@ -126,7 +126,7 @@ private static async Task DoWaitAsync(this Task task, CancellationToken cancella

public static Task WaitAsync(this Task task, TimeSpan timeout)
{
#if NET6_0_OR_GREATER
#if NET
if (task.IsCompletedSuccessfully)
{
return task;
Expand Down Expand Up @@ -171,7 +171,7 @@ public static async ValueTask TimeoutAfter(this ValueTask valueTask, TimeSpan ti
return;
}

#if NET6_0_OR_GREATER
#if NET
Task task = valueTask.AsTask();
await task.WaitAsync(timeout)
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/TcpClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TcpClientAdapter(Socket socket)
_sock = socket ?? throw new InvalidOperationException("socket must not be null");
}

#if NET6_0_OR_GREATER
#if NET
public virtual Task ConnectAsync(IPAddress ep, int port, CancellationToken cancellationToken = default)
{
return _sock.ConnectAsync(ep, port, cancellationToken).AsTask();
Expand Down
1 change: 1 addition & 0 deletions projects/Test/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="EasyNetQ.Management.Client" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.abstractions" />
Expand Down
2 changes: 1 addition & 1 deletion projects/Test/Common/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public abstract class IntegrationFixture : IAsyncLifetime
static IntegrationFixture()
{

#if NET6_0_OR_GREATER
#if NET
S_Random = Random.Shared;
#else
S_Random = new Random();
Expand Down
2 changes: 1 addition & 1 deletion projects/Test/Common/TestOutputWriterEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
try
{
#if NET6_0_OR_GREATER
#if NET
if (eventData.Payload.Count > 0)
{
string payloadName = eventData.PayloadNames[0];
Expand Down
1 change: 1 addition & 0 deletions projects/Test/Integration/Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
-->

<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
Expand Down
27 changes: 25 additions & 2 deletions projects/Test/Integration/TestExchangeDeclare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
var exchangeNames = new ConcurrentBag<string>();
var tasks = new List<Task>();
NotSupportedException nse = null;
Exception unexpectedException = null;
for (int i = 0; i < 256; i++)
{
var t = Task.Run(async () =>
Expand All @@ -129,13 +130,24 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
{
nse = e;
}
catch (Exception ex)
{
unexpectedException = ex;
}
});
tasks.Add(t);
}

await Task.WhenAll(tasks);

Assert.Null(nse);
if (nse is not null)
{
Assert.Fail($"got unexpected NotSupportedException: {nse}");
}
if (unexpectedException is not null)
{
Assert.Fail($"got unexpected Exception: {unexpectedException}");
}
tasks.Clear();

foreach (string exchangeName in exchangeNames)
Expand All @@ -154,13 +166,24 @@ public async Task TestConcurrentExchangeDeclareAndDelete()
{
nse = e;
}
catch (Exception ex)
{
unexpectedException = ex;
}
});
tasks.Add(t);
}

await Task.WhenAll(tasks);

Assert.Null(nse);
if (nse is not null)
{
Assert.Fail($"got unexpected NotSupportedException: {nse}");
}
if (unexpectedException is not null)
{
Assert.Fail($"got unexpected Exception: {unexpectedException}");
}
}
}
}
1 change: 1 addition & 0 deletions projects/Test/OAuth2/OAuth2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Text.RegularExpressions" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<SignAssembly>true</SignAssembly>
<IsTestProject>true</IsTestProject>
<LangVersion>12.0</LangVersion>
<TestTfmsInParallel>false</TestTfmsInParallel>
</PropertyGroup>

<ItemGroup>
Expand All @@ -38,6 +39,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="OpenTelemetry.Exporter.InMemory" />
<PackageReference Include="xunit" />
Expand Down
1 change: 1 addition & 0 deletions projects/Test/Unit/Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
Expand Down

0 comments on commit dc89271

Please sign in to comment.