Skip to content

Add net8.0 target and increase net47 to net472 #1128

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 15 commits into from
Jun 13, 2025
Merged
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
run: dotnet build src/NetMQ.sln /p:Configuration=Release /verbosity:minimal
- name: test net9.0
run: dotnet test -v n -p:ParallelizeTestCollections=false --configuration Release --no-build -f net9.0 src\NetMQ.Tests\NetMQ.Tests.csproj
- name: test net47
run: dotnet test -v n -p:ParallelizeTestCollections=false --configuration Release --no-build -f net47 src\NetMQ.Tests\NetMQ.Tests.csproj
- name: test net472
run: dotnet test -v n -p:ParallelizeTestCollections=false --configuration Release --no-build -f net472 src\NetMQ.Tests\NetMQ.Tests.csproj
- name: coverage
run: |
OpenCover.Console.exe -register:user -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test --no-build --configuration Release -f net6.0 --logger:trx;LogFileName=results.trx /p:DebugType=full src\NetMQ.Tests\NetMQ.Tests.csproj" -filter:"+[NetMQ*]* -[NetMQ.Tests*]*" -output:".\NetMQ_coverage.xml" -oldStyle
Expand Down
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions src/NetMQ.Tests/ClientServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Tcp()
}

[Fact]
public async void Async()
public async Task Async()
{
using var server = new ServerSocket();
using var client = new ClientSocket();
Expand All @@ -72,7 +72,7 @@ public async void Async()
}

[Fact]
public async void AsyncWithCancellationToken()
public async Task AsyncWithCancellationToken()
{
using CancellationTokenSource source = new CancellationTokenSource();
using var server = new ServerSocket();
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ.Tests/CurveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using NetMQ.Sockets;
using Xunit;

#if NET47
#if NETFRAMEWORK
using ZeroMQ;
#endif

Expand Down Expand Up @@ -39,7 +39,7 @@ public void CurveTest()

}

#if NET47
#if NETFRAMEWORK
[Fact]
public void WithLibzmqClient()
{
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ.Tests/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void Issue52_ReqToRouterBug()

var msg = router.ReceiveMultipartMessage();
Assert.Equal(3, msg.FrameCount);
Assert.Equal(msg[2].ConvertToString(), testmessage);
Assert.Equal(testmessage, msg[2].ConvertToString());
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/NetMQ.Tests/NetMQ.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsTestProject>true</IsTestProject>
<TargetFrameworks>net9.0;net47</TargetFrameworks>
<TargetFrameworks>net9.0;net472</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -20,13 +20,13 @@
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND '$(TargetIsMono)' == 'true' AND EXISTS('/usr/lib/mono')">/usr/lib/mono</BaseFrameworkPathOverrideForMono>
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND '$(TargetIsMono)' == 'true' AND EXISTS('/usr/local/lib/mono')">/usr/local/lib/mono</BaseFrameworkPathOverrideForMono>

<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net47'">$(BaseFrameworkPathOverrideForMono)/4.7-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net472'">$(BaseFrameworkPathOverrideForMono)/4.7-api</FrameworkPathOverride>

<!-- Add the Facades directory. Not sure how else to do this. Necessary at least for .NET 4.5 -->
<AssemblySearchPaths Condition="'$(BaseFrameworkPathOverrideForMono)' != ''">$(FrameworkPathOverride)/Facades;$(AssemblySearchPaths)</AssemblySearchPaths>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -39,14 +39,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
<PackageReference Include="xunit" Version="2.4.2-pre.13" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="ZeroMQ" Version="4.1.0.31" />
</ItemGroup>

Expand Down
21 changes: 12 additions & 9 deletions src/NetMQ.Tests/NetMQMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public void Monitoring()
}
}

#if !NET35

[Fact]
public void StartAsync()
public async Task StartAsync()
{
using (var rep = new ResponseSocket())
using (var monitor = new NetMQMonitor(rep, "inproc://foo", SocketEvents.Closed))
Expand All @@ -68,10 +68,11 @@ public void StartAsync()
Thread.Sleep(200);
Assert.Equal(TaskStatus.Running, task.Status);
monitor.Stop();
Assert.True(task.Wait(TimeSpan.FromMilliseconds(1000)));
var completedTask = await Task.WhenAny(task, Task.Delay(1000));
Assert.Equal(task, completedTask);
}
}
#endif


[Fact]
public void NoHangWhenMonitoringUnboundInprocAddress()
Expand Down Expand Up @@ -126,7 +127,7 @@ public void ErrorCodeTest()
}

[Fact]
public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
public async Task MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
{
// The bug:
// Given we monitor a netmq tcp socket
Expand All @@ -141,7 +142,7 @@ public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
using (var req = new RequestSocket())
{
monitor = new NetMQMonitor(req, "inproc://#monitor", SocketEvents.All);
Task.Factory.StartNew(monitor.Start);
_ = Task.Factory.StartNew(monitor.Start);

// Bug only occurs when monitoring a tcp socket
var port = res.BindRandomPort("tcp://127.0.0.1");
Expand All @@ -152,10 +153,12 @@ public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
res.SendFrame("response");
Assert.Equal("response", req.ReceiveFrameString());
}
Thread.Sleep(100);

await Task.Delay(100);
// Monitor.Dispose should complete
var completed = Task.Factory.StartNew(() => monitor.Dispose()).Wait(1000);
Assert.True(completed);
var task = Task.Factory.StartNew(() => monitor.Dispose());
var completedTask = await Task.WhenAny(task, Task.Delay(1000));
Assert.Equal(task, completedTask);
}
// NOTE If this test fails, it will hang because context.Dispose will block
}
Expand Down
31 changes: 15 additions & 16 deletions src/NetMQ.Tests/NetMQPollerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#if !NET35
using System.Collections.Concurrent;
using System.Collections.Generic;
#endif

// ReSharper disable AccessToDisposedClosure
Expand Down Expand Up @@ -318,7 +319,7 @@ public void AddTwoSocketAfterRemoving()


[Fact]
public void RemoveSocket()
public async Task RemoveSocket()
{
using (var router1 = new RouterSocket())
using (var router2 = new RouterSocket())
Expand Down Expand Up @@ -395,8 +396,8 @@ public void RemoveSocket()

poller.Stop();
// await the pollerTask, 1ms should suffice
pollerTask.Wait(1);
Assert.True(pollerTask.IsCompleted);
var completedTask = await Task.WhenAny(pollerTask, Task.Delay(1));
Assert.Equal(pollerTask, completedTask);
}
}

Expand Down Expand Up @@ -865,7 +866,7 @@ public void NativeSocket()

#if !NET35
[Fact]
public void OneTask()
public async Task OneTask()
{
bool triggered = false;

Expand All @@ -879,27 +880,27 @@ public void OneTask()
Assert.True(poller.CanExecuteTaskInline, "Should be on NetMQPoller thread");
});
task.Start(poller);
task.Wait();
await task;

Assert.True(triggered);
}
}

[Fact]
public void SetsCurrentTaskScheduler()
public async Task SetsCurrentTaskScheduler()
{
using (var poller = new NetMQPoller())
{
poller.RunAsync();

var task = new Task(() => Assert.Same(TaskScheduler.Current, poller));
task.Start(poller);
task.Wait();
await task;
}
}

[Fact]
public void CanExecuteTaskInline()
public async Task CanExecuteTaskInline()
{
using (var poller = new NetMQPoller())
{
Expand All @@ -911,12 +912,12 @@ public void CanExecuteTaskInline()

var task = new Task(() => Assert.True(poller.CanExecuteTaskInline));
task.Start(poller);
task.Wait();
await task;
}
}

[Fact]
public void ContinueWith()
public async Task ContinueWith()
{
int threadId1 = 0;
int threadId2 = 1;
Expand All @@ -941,8 +942,7 @@ public void ContinueWith()
}, poller);

task.Start(poller);
task.Wait();
task2.Wait();
await Task.WhenAll(new List<Task>{task, task2});

Assert.Equal(threadId1, threadId2);
Assert.Equal(1, runCount1);
Expand All @@ -951,7 +951,7 @@ public void ContinueWith()
}

[Fact]
public void TwoThreads()
public async Task TwoThreads()
{
int count1 = 0;
int count2 = 0;
Expand Down Expand Up @@ -982,9 +982,8 @@ public void TwoThreads()
}
});

t1.Wait(1000);
t2.Wait(1000);
Task.WaitAll(allTasks.ToArray(), 1000);
await Task.WhenAny(Task.WhenAll(new List<Task>{ t1, t2 }), Task.Delay(1000));
await Task.WhenAny(Task.WhenAll(allTasks.ToArray()), Task.Delay(1000));

Assert.Equal(100, count1);
Assert.Equal(100, count2);
Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ.Tests/NetMQQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void EnqueueDequeue()
}

[Fact]
public void EnqueueShouldNotBlockWhenCapacityIsZero()
public async Task EnqueueShouldNotBlockWhenCapacityIsZero()
{
using (var mockSocket = new PairSocket())
using (var queue = new NetMQQueue<int>())
Expand All @@ -39,8 +39,8 @@ public void EnqueueShouldNotBlockWhenCapacityIsZero()
}
});

bool completed = task.Wait(TimeSpan.FromSeconds(1));
Assert.True(completed, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
var completedTask = await Task.WhenAny(task, Task.Delay(1000));
Assert.True(task == completedTask, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/NetMQ.Tests/PgmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void TwoPublishers()
}

[Fact(Skip = "Requires MSMQ for PGM sockets")]
public void Sending1000Messages()
public async Task Sending1000Messages()
{
// creating two different context and sending 1000 messages

Expand Down Expand Up @@ -230,8 +230,8 @@ public void Sending1000Messages()
}
});

pubTask.Wait();
subTask.Wait();
await pubTask;
await subTask;

Assert.Equal(1000, count);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public void LargeMessage()
[Theory(Skip = "Requires MSMQ for PGM sockets")]
[InlineData("pgm://239.0.0.1:1000")]
[InlineData("tcp://localhost:60000")]
public void SubscriberCleanupOnUnbind(string address)
public async Task SubscriberCleanupOnUnbind(string address)
{
for (var i = 0; i < 10; i++)
{
Expand All @@ -290,8 +290,8 @@ public void SubscriberCleanupOnUnbind(string address)
// var duration = DateTime.Now - time;

monitor.Stop();

monitorTask.Wait();
await monitorTask;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/NetMQ.Tests/RadioDish.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NetMQ.Sockets;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void TestBlocking()
}

[Fact]
public async void TestAsync()
public async Task TestAsync()
{
using var radio = new RadioSocket();
using var dish = new DishSocket();
Expand All @@ -56,7 +57,7 @@ public async void TestAsync()
int port = radio.BindRandomPort("tcp://*");
dish.Connect($"tcp://127.0.0.1:{port}");

Thread.Sleep(100);
await Task.Delay(100);

await radio.SendAsync("1", "HELLO");
await radio.SendAsync("2", "HELLO");
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ.Tests/RouterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ReceiveReadyDot35Bug()
using (var server = new RouterSocket())
{
server.BindRandomPort("tcp://127.0.0.1");
server.ReceiveReady += (s, e) => Assert.True(false, "Should not receive");
server.ReceiveReady += (s, e) => Assert.Fail( "Should not receive");

Assert.False(server.Poll(TimeSpan.FromMilliseconds(1500)));
}
Expand Down
Loading
Loading