Skip to content

Ensure target frameworks make sense for 7.0 #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}}
11 changes: 5 additions & 6 deletions projects/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<OutputType>Exe</OutputType>
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<TargetFrameworks>netcoreapp3.1;net48</TargetFrameworks>
<ReleaseVersion>8.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Ductus.FluentDocker" Version="2.7.3" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Ductus.FluentDocker" Version="2.10.45" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RabbitMQ.Client\RabbitMQ.Client.csproj" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>

</Project>
22 changes: 7 additions & 15 deletions projects/RabbitMQ.Client/RabbitMQ.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyTitle>RabbitMQ Client Library for .NET</AssemblyTitle>
Expand Down Expand Up @@ -36,11 +36,6 @@
<Deterministic>true</Deterministic>
</PropertyGroup>

<!-- disable nullable warnings for .NET Standard 2.0 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<NoWarn>$(NoWarn);nullable</NoWarn>
</PropertyGroup>

<Target Name="SetVersionFromConcourseData" AfterTargets="MinVer" Condition="'$(CONCOURSE_PULL_REQUEST_NUMBER)' != ''">
<PropertyGroup>
<PackageVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch)-$(MinVerPreRelease)-pr.$(CONCOURSE_PULL_REQUEST_NUMBER)</PackageVersion>
Expand All @@ -62,15 +57,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.4.0" PrivateAssets="All" />
<PackageReference Include="System.Threading.Channels" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="3.1.0" PrivateAssets="All" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion projects/TestApplications/MassPublish/MassPublish.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions projects/Unit/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion projects/Unit/RabbitMQCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Process> s_invokeRabbitMqCtl = GetRabbitMqCtlInvokeAction();

private static Func<string, Process> GetRabbitMqCtlInvokeAction()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion projects/Unit/TestBlockingCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void TestBackgroundUpdateSucceedsWithInfiniteTimeoutTimeSpan()
public void TestBackgroundUpdateFails()
{
var k = new BlockingCell<int>();
SetAfter(TimingInterval_2X, k, 123);
SetAfter(TimingInterval_4X, k, 123);

ResetTimer();
Assert.Throws<TimeoutException>(() => k.WaitForValue(TimingInterval));
Expand Down
2 changes: 0 additions & 2 deletions projects/Unit/TestChannelAllocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

namespace RabbitMQ.Client.Unit
{


public class TestIModelAllocation : IDisposable
{
public const int CHANNEL_COUNT = 100;
Expand Down
110 changes: 61 additions & 49 deletions projects/Unit/TestPublisherConfirms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<TaskCanceledException>(() => ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult());
using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)))
{
Assert.Throws<TaskCanceledException>(() => ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult());
}
});
}

Expand All @@ -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<IModel> fn)
{
IModel ch = _conn.CreateModel();
ch.ConfirmSelect();
ch.QueueDeclare(QueueName);

ReadOnlyMemory<byte> 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);
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions projects/Unit/Unit.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>latest</LangVersion>
Expand All @@ -13,15 +13,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="PublicApiGenerator" Version="10.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Verify.Xunit" Version="11.18.2" />
<PackageReference Include="Verify.Xunit" Version="16.5.4" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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