diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index b2b20fe478..02505b0e07 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,7 +22,7 @@ jobs: with: submodules: true - name: Cache installers - uses: actions/cache@v2 + uses: actions/cache@v3 with: # Note: the cache path is relative to the workspace directory # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#using-the-cache-action @@ -66,11 +66,11 @@ jobs: with: submodules: true - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: 3.1.x + dotnet-version: 6.x - name: Cache NuGet packages - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.nuget/packages @@ -83,6 +83,6 @@ jobs: - name: Build run: dotnet build --no-restore --verbosity=normal - name: Test - run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed" --framework "netcoreapp3.1" + run: dotnet test --no-restore --no-build --logger "console;verbosity=detailed" --framework "net6.0" env: RABBITMQ_RABBITMQCTL_PATH: DOCKER:${{job.services.rabbitmq.id}} diff --git a/projects/Benchmarks/Benchmarks.csproj b/projects/Benchmarks/Benchmarks.csproj index 4d7ffbd508..1d0891f8c6 100644 --- a/projects/Benchmarks/Benchmarks.csproj +++ b/projects/Benchmarks/Benchmarks.csproj @@ -1,21 +1,20 @@ - + + net6.0;net472 Exe ../rabbit.snk true - netcoreapp3.1;net48 - 8.0 - - + + - + diff --git a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj index 1f738fc412..4365900ea6 100644 --- a/projects/RabbitMQ.Client/RabbitMQ.Client.csproj +++ b/projects/RabbitMQ.Client/RabbitMQ.Client.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.1;netstandard2.0 + net6.0;netstandard2.0 $(NoWarn);CS1591 true RabbitMQ Client Library for .NET @@ -36,11 +36,6 @@ true - - - $(NoWarn);nullable - - $(MinVerMajor).$(MinVerMinor).$(MinVerPatch)-$(MinVerPreRelease)-pr.$(CONCOURSE_PULL_REQUEST_NUMBER) @@ -62,15 +57,12 @@ - - - - - - - - + + + + + diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index e0389186c5..78f8a7d3e1 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -170,7 +170,7 @@ private IAuthMechanismFactory GetAuthMechanismFactory(string supportedMechanismN // Our list is in order of preference, the server one is not. foreach (var factory in _config.AuthMechanisms) { - if (supportedMechanismNames.Contains(factory.Name, StringComparison.OrdinalIgnoreCase)) + if (supportedMechanismNames.IndexOf(factory.Name, StringComparison.OrdinalIgnoreCase) >= 0) { return factory; } diff --git a/projects/TestApplications/CreateChannel/CreateChannel.csproj b/projects/TestApplications/CreateChannel/CreateChannel.csproj index a3356ad2d1..157ff7d8f0 100644 --- a/projects/TestApplications/CreateChannel/CreateChannel.csproj +++ b/projects/TestApplications/CreateChannel/CreateChannel.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net6.0;net472 diff --git a/projects/TestApplications/MassPublish/MassPublish.csproj b/projects/TestApplications/MassPublish/MassPublish.csproj index a3356ad2d1..157ff7d8f0 100644 --- a/projects/TestApplications/MassPublish/MassPublish.csproj +++ b/projects/TestApplications/MassPublish/MassPublish.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net6.0;net472 diff --git a/projects/Unit/Fixtures.cs b/projects/Unit/Fixtures.cs index 29172868d3..fbe7859233 100644 --- a/projects/Unit/Fixtures.cs +++ b/projects/Unit/Fixtures.cs @@ -423,6 +423,7 @@ public class TimingFixture { public static readonly TimeSpan TimingInterval = TimeSpan.FromMilliseconds(300); public static readonly TimeSpan TimingInterval_2X = TimeSpan.FromMilliseconds(600); + public static readonly TimeSpan TimingInterval_4X = TimeSpan.FromMilliseconds(1200); public static readonly TimeSpan SafetyMargin = TimeSpan.FromMilliseconds(150); public static readonly TimeSpan TestTimeout = TimeSpan.FromSeconds(5); } diff --git a/projects/Unit/RabbitMQCtl.cs b/projects/Unit/RabbitMQCtl.cs index a311196c7a..8328038d05 100644 --- a/projects/Unit/RabbitMQCtl.cs +++ b/projects/Unit/RabbitMQCtl.cs @@ -43,6 +43,7 @@ namespace RabbitMQ.Client.Unit #nullable enable public static class RabbitMQCtl { + private static readonly char[] newLine = new char[] { '\n' }; private static readonly Func s_invokeRabbitMqCtl = GetRabbitMqCtlInvokeAction(); private static Func GetRabbitMqCtlInvokeAction() @@ -209,7 +210,8 @@ public static void CloseAllConnections() private static string[] EnumerateConnectionsPid() { - return ExecRabbitMQCtl("list_connections --silent pid").Split('\n', StringSplitOptions.RemoveEmptyEntries); + string rabbitmqCtlResult = ExecRabbitMQCtl("list_connections --silent pid"); + return rabbitmqCtlResult.Split(newLine, StringSplitOptions.RemoveEmptyEntries); } public static void RestartRabbitMQ() diff --git a/projects/Unit/TestBlockingCell.cs b/projects/Unit/TestBlockingCell.cs index 49cb99a168..d21d741ef3 100644 --- a/projects/Unit/TestBlockingCell.cs +++ b/projects/Unit/TestBlockingCell.cs @@ -164,7 +164,7 @@ public void TestBackgroundUpdateSucceedsWithInfiniteTimeoutTimeSpan() public void TestBackgroundUpdateFails() { var k = new BlockingCell(); - SetAfter(TimingInterval_2X, k, 123); + SetAfter(TimingInterval_4X, k, 123); ResetTimer(); Assert.Throws(() => k.WaitForValue(TimingInterval)); diff --git a/projects/Unit/TestChannelAllocation.cs b/projects/Unit/TestChannelAllocation.cs index df51ff8d8b..ed1ca99ff4 100644 --- a/projects/Unit/TestChannelAllocation.cs +++ b/projects/Unit/TestChannelAllocation.cs @@ -38,8 +38,6 @@ namespace RabbitMQ.Client.Unit { - - public class TestIModelAllocation : IDisposable { public const int CHANNEL_COUNT = 100; diff --git a/projects/Unit/TestPublisherConfirms.cs b/projects/Unit/TestPublisherConfirms.cs index 5f67355a48..2996cd3a6f 100644 --- a/projects/Unit/TestPublisherConfirms.cs +++ b/projects/Unit/TestPublisherConfirms.cs @@ -45,9 +45,14 @@ namespace RabbitMQ.Client.Unit public class TestPublisherConfirms : IntegrationFixture { private const string QueueName = "RabbitMQ.Client.Unit.TestPublisherConfirms"; + private readonly byte[] _body; public TestPublisherConfirms(ITestOutputHelper output) : base(output) { + var rnd = new Random(); + _body = new byte[4096]; + rnd.NextBytes(_body); + } [Fact] @@ -64,18 +69,22 @@ public void TestWaitForConfirmsWithTimeout() { TestWaitForConfirms(200, (ch) => { - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4)); - Assert.True(ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4))) + { + Assert.True(ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + } }); } [Fact] public void TestWaitForConfirmsWithTimeout_AllMessagesAcked_WaitingHasTimedout_ReturnTrue() { - TestWaitForConfirms(2000, (ch) => + TestWaitForConfirms(10000, (ch) => { - using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); - Assert.Throws(() => ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1))) + { + Assert.Throws(() => ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + } }); } @@ -90,67 +99,70 @@ public void TestWaitForConfirmsWithTimeout_MessageNacked_WaitingHasTimedout_Retu .GetMethod("HandleAckNack", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(actualModel, new object[] { 10UL, false, true }); - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4)); - Assert.False(ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4))) + { + Assert.False(ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult()); + } }); } [Fact] public async Task TestWaitForConfirmsWithEvents() { - IModel ch = _conn.CreateModel(); - ch.ConfirmSelect(); + using (IModel ch = _conn.CreateModel()) + { + ch.ConfirmSelect(); - ch.QueueDeclare(QueueName); - int n = 200; - // number of event handler invocations - int c = 0; + ch.QueueDeclare(QueueName); + int n = 200; + // number of event handler invocations + int c = 0; - ch.BasicAcks += (_, args) => - { - Interlocked.Increment(ref c); - }; - try - { - for (int i = 0; i < n; i++) + ch.BasicAcks += (_, args) => + { + Interlocked.Increment(ref c); + }; + try { - ch.BasicPublish("", QueueName, _encoding.GetBytes("msg")); + for (int i = 0; i < n; i++) + { + ch.BasicPublish("", QueueName, _encoding.GetBytes("msg")); + } + await ch.WaitForConfirmsAsync().ConfigureAwait(false); + + // Note: number of event invocations is not guaranteed + // to be equal to N because acks can be batched, + // so we primarily care about event handlers being invoked + // in this test + Assert.True(c > 5); + } + finally + { + ch.QueueDelete(QueueName); } - await ch.WaitForConfirmsAsync().ConfigureAwait(false); - - // Note: number of event invocations is not guaranteed - // to be equal to N because acks can be batched, - // so we primarily care about event handlers being invoked - // in this test - Assert.True(c > 5); - } - finally - { - ch.QueueDelete(QueueName); - ch.Close(); } } protected void TestWaitForConfirms(int numberOfMessagesToPublish, Action fn) { - IModel ch = _conn.CreateModel(); - ch.ConfirmSelect(); - ch.QueueDeclare(QueueName); - - ReadOnlyMemory body = _encoding.GetBytes("msg"); - for (int i = 0; i < numberOfMessagesToPublish; i++) + using (IModel ch = _conn.CreateModel()) { - ch.BasicPublish("", QueueName, body); - } + ch.ConfirmSelect(); + ch.QueueDeclare(QueueName); - try - { - fn(ch); - } - finally - { - ch.QueueDelete(QueueName); - ch.Close(); + for (int i = 0; i < numberOfMessagesToPublish; i++) + { + ch.BasicPublish("", QueueName, _body); + } + + try + { + fn(ch); + } + finally + { + ch.QueueDelete(QueueName); + } } } } diff --git a/projects/Unit/Unit.csproj b/projects/Unit/Unit.csproj index 32e0b4fb6e..dcc0301893 100644 --- a/projects/Unit/Unit.csproj +++ b/projects/Unit/Unit.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.1 + net6.0;net472 ../rabbit.snk true latest @@ -13,15 +13,15 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/run-test.sh b/run-test.sh index c2a2146015..56db81db23 100755 --- a/run-test.sh +++ b/run-test.sh @@ -13,4 +13,4 @@ fi cd "$script_dir" -dotnet test --no-build --logger 'console;verbosity=detailed' --framework 'netcoreapp3.1' ./RabbitMQDotNetClient.sln < /dev/null +dotnet test --no-build --logger 'console;verbosity=detailed' --framework 'net6.0' ./RabbitMQDotNetClient.sln < /dev/null