Skip to content

Commit fb96e78

Browse files
committed
Upgrade xunit to 2.8.0 and fix compiler warnings
1 parent 33d1e9b commit fb96e78

13 files changed

+104
-32
lines changed

src/NetMQ.Tests/ClientServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Tcp()
5454
}
5555

5656
[Fact]
57-
public async void Async()
57+
public async Task Async()
5858
{
5959
using var server = new ServerSocket();
6060
using var client = new ClientSocket();
@@ -72,7 +72,7 @@ public async void Async()
7272
}
7373

7474
[Fact]
75-
public async void AsyncWithCancellationToken()
75+
public async Task AsyncWithCancellationToken()
7676
{
7777
using CancellationTokenSource source = new CancellationTokenSource();
7878
using var server = new ServerSocket();
@@ -85,7 +85,7 @@ public async void AsyncWithCancellationToken()
8585
#if NETCOREAPP3_1
8686

8787
[Fact(Timeout = 120)]
88-
public async void AsyncEnumerableCanceled()
88+
public async Task AsyncEnumerableCanceled()
8989
{
9090
using CancellationTokenSource source = new CancellationTokenSource();
9191
using var server = new ServerSocket();

src/NetMQ.Tests/MessageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void Issue52_ReqToRouterBug()
128128

129129
var msg = router.ReceiveMultipartMessage();
130130
Assert.Equal(3, msg.FrameCount);
131-
Assert.Equal(msg[2].ConvertToString(), testmessage);
131+
Assert.Equal(testmessage, msg[2].ConvertToString());
132132
}
133133
}
134134

src/NetMQ.Tests/NetMQ.Tests.csproj

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!-- have to teachcd MSBuild where the Mono copy of the reference asssemblies is -->
1616
<TargetIsMono Condition="$(TargetFramework.StartsWith('net4')) and '$(OS)' == 'Unix'">true</TargetIsMono>
1717

18-
<!-- Look in the standard install locations -->
18+
<!-- Look in the standard install locations -->
1919
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND '$(TargetIsMono)' == 'true' AND EXISTS('/Library/Frameworks/Mono.framework/Versions/Current/lib/mono')">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono</BaseFrameworkPathOverrideForMono>
2020
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND '$(TargetIsMono)' == 'true' AND EXISTS('/usr/lib/mono')">/usr/lib/mono</BaseFrameworkPathOverrideForMono>
2121
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND '$(TargetIsMono)' == 'true' AND EXISTS('/usr/local/lib/mono')">/usr/local/lib/mono</BaseFrameworkPathOverrideForMono>
@@ -39,14 +39,28 @@
3939
</ItemGroup>
4040

4141
<ItemGroup>
42-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
43-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
44-
<PackageReference Include="xunit" Version="2.4.2-pre.13" />
45-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
42+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
43+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4644
</ItemGroup>
47-
45+
4846
<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
4947
<PackageReference Include="ZeroMQ" Version="4.1.0.31" />
5048
</ItemGroup>
5149

50+
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1' ">
51+
<PackageReference Include="xunit" Version="2.8.0" />
52+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
53+
<PrivateAssets>all</PrivateAssets>
54+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
55+
</PackageReference>
56+
</ItemGroup>
57+
58+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
59+
<PackageReference Include="xunit" Version="2.4.2" />
60+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
61+
<PrivateAssets>all</PrivateAssets>
62+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
63+
</PackageReference>
64+
</ItemGroup>
65+
5266
</Project>

src/NetMQ.Tests/NetMQMonitorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void StartAsync()
6868
Thread.Sleep(200);
6969
Assert.Equal(TaskStatus.Running, task.Status);
7070
monitor.Stop();
71-
Assert.True(task.Wait(TimeSpan.FromMilliseconds(1000)));
71+
Assert.True(TaskUtils.Wait(task, TimeSpan.FromMilliseconds(1000)));
7272
}
7373
}
7474
#endif
@@ -154,7 +154,7 @@ public void MonitorDisposeProperlyWhenDisposedAfterMonitoredTcpSocket()
154154
}
155155
Thread.Sleep(100);
156156
// Monitor.Dispose should complete
157-
var completed = Task.Factory.StartNew(() => monitor.Dispose()).Wait(1000);
157+
var completed = TaskUtils.Wait(Task.Factory.StartNew(() => monitor.Dispose()), TimeSpan.FromMilliseconds(1000));
158158
Assert.True(completed);
159159
}
160160
// NOTE If this test fails, it will hang because context.Dispose will block

src/NetMQ.Tests/NetMQPollerTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void RemoveSocket()
395395

396396
poller.Stop();
397397
// await the pollerTask, 1ms should suffice
398-
pollerTask.Wait(1);
398+
TaskUtils.Wait(pollerTask, TimeSpan.FromMilliseconds(1));
399399
Assert.True(pollerTask.IsCompleted);
400400
}
401401
}
@@ -879,7 +879,7 @@ public void OneTask()
879879
Assert.True(poller.CanExecuteTaskInline, "Should be on NetMQPoller thread");
880880
});
881881
task.Start(poller);
882-
task.Wait();
882+
TaskUtils.Wait(task);
883883

884884
Assert.True(triggered);
885885
}
@@ -894,7 +894,7 @@ public void SetsCurrentTaskScheduler()
894894

895895
var task = new Task(() => Assert.Same(TaskScheduler.Current, poller));
896896
task.Start(poller);
897-
task.Wait();
897+
TaskUtils.Wait(task);
898898
}
899899
}
900900

@@ -911,7 +911,7 @@ public void CanExecuteTaskInline()
911911

912912
var task = new Task(() => Assert.True(poller.CanExecuteTaskInline));
913913
task.Start(poller);
914-
task.Wait();
914+
TaskUtils.Wait(task);
915915
}
916916
}
917917

@@ -941,8 +941,8 @@ public void ContinueWith()
941941
}, poller);
942942

943943
task.Start(poller);
944-
task.Wait();
945-
task2.Wait();
944+
TaskUtils.Wait(task);
945+
TaskUtils.Wait(task2);
946946

947947
Assert.Equal(threadId1, threadId2);
948948
Assert.Equal(1, runCount1);
@@ -982,9 +982,9 @@ public void TwoThreads()
982982
}
983983
});
984984

985-
t1.Wait(1000);
986-
t2.Wait(1000);
987-
Task.WaitAll(allTasks.ToArray(), 1000);
985+
TaskUtils.Wait(t1, TimeSpan.FromMilliseconds(1000));
986+
TaskUtils.Wait(t2, TimeSpan.FromMilliseconds(1000));
987+
TaskUtils.WaitAll(allTasks, TimeSpan.FromMilliseconds(1000));
988988

989989
Assert.Equal(100, count1);
990990
Assert.Equal(100, count2);

src/NetMQ.Tests/NetMQQueueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void EnqueueShouldNotBlockWhenCapacityIsZero()
3939
}
4040
});
4141

42-
bool completed = task.Wait(TimeSpan.FromSeconds(1));
42+
bool completed = TaskUtils.Wait(task, TimeSpan.FromSeconds(1));
4343
Assert.True(completed, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
4444
}
4545
}

src/NetMQ.Tests/PgmTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public void Sending1000Messages()
230230
}
231231
});
232232

233-
pubTask.Wait();
234-
subTask.Wait();
233+
TaskUtils.Wait(pubTask);
234+
TaskUtils.Wait(subTask);
235235

236236
Assert.Equal(1000, count);
237237
}
@@ -291,7 +291,7 @@ public void SubscriberCleanupOnUnbind(string address)
291291

292292
monitor.Stop();
293293

294-
monitorTask.Wait();
294+
TaskUtils.Wait(monitorTask);
295295
}
296296
}
297297
}

src/NetMQ.Tests/RadioDish.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading;
3+
using System.Threading.Tasks;
34
using NetMQ.Sockets;
45
using Xunit;
56
using Xunit.Abstractions;
@@ -47,7 +48,7 @@ public void TestBlocking()
4748
}
4849

4950
[Fact]
50-
public async void TestAsync()
51+
public async Task TestAsync()
5152
{
5253
using var radio = new RadioSocket();
5354
using var dish = new DishSocket();

src/NetMQ.Tests/RouterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void ReceiveReadyDot35Bug()
4444
using (var server = new RouterSocket())
4545
{
4646
server.BindRandomPort("tcp://127.0.0.1");
47-
server.ReceiveReady += (s, e) => Assert.True(false, "Should not receive");
47+
server.ReceiveReady += (s, e) => Assert.Fail("Should not receive");
4848

4949
Assert.False(server.Poll(TimeSpan.FromMilliseconds(1500)));
5050
}

src/NetMQ.Tests/ScatterGather.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Threading;
2+
using System.Threading.Tasks;
23
using NetMQ.Sockets;
34
using Xunit;
45

@@ -47,7 +48,7 @@ public void TestBlocking()
4748
}
4849

4950
[Fact]
50-
public async void TestAsync()
51+
public async Task TestAsync()
5152
{
5253
using var scatter = new ScatterSocket();
5354
using var gather = new GatherSocket();

src/NetMQ.Tests/SocketTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void ReceiveMessageWithTimeout()
134134
t1.Start();
135135
t2.Start();
136136

137-
Task.WaitAll(t1, t2);
137+
TaskUtils.WaitAll(new[]{t1, t2});
138138
}
139139
}
140140

src/NetMQ.Tests/TaskUtils.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace NetMQ.Tests
8+
{
9+
internal class TaskUtils
10+
{
11+
internal static async Task PollUntil(Func<bool> condition, TimeSpan timeout)
12+
{
13+
var cts = new CancellationTokenSource();
14+
cts.CancelAfter(timeout);
15+
16+
await PollUntil(condition, cts.Token);
17+
}
18+
19+
internal static async Task PollUntil(Func<bool> condition, CancellationToken ct = default)
20+
{
21+
try
22+
{
23+
while (!condition())
24+
{
25+
await Task.Delay(25, ct).ConfigureAwait(true);
26+
}
27+
}
28+
catch (TaskCanceledException)
29+
{
30+
// Task was cancelled. Ignore exception and return.
31+
}
32+
}
33+
34+
internal static bool WaitAll(IEnumerable<Task> tasks, TimeSpan timeout)
35+
{
36+
PollUntil(() => tasks.All(t => t.IsCompleted), timeout).Wait();
37+
return tasks.All(t => t.Status == TaskStatus.RanToCompletion);
38+
}
39+
40+
internal static void WaitAll(IEnumerable<Task> tasks)
41+
{
42+
PollUntil(() => tasks.All(t => t.IsCompleted), Timeout.InfiniteTimeSpan).Wait();
43+
}
44+
45+
internal static bool Wait(Task task, TimeSpan timeout)
46+
{
47+
PollUntil(() => task.IsCompleted, timeout).Wait();
48+
return task.Status == TaskStatus.RanToCompletion;
49+
}
50+
51+
internal static void Wait(Task task)
52+
{
53+
PollUntil(() => task.IsCompleted, Timeout.InfiniteTimeSpan).Wait();
54+
}
55+
}
56+
}

src/NetMQ.Tests/XPubSubTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void Manual()
332332
sub.SendFrame(new byte[] { 1, (byte)'A' });
333333
var subscription = pub.ReceiveFrameBytes();
334334

335-
Assert.Equal(subscription[1], (byte)'A');
335+
Assert.Equal((byte)'A', subscription[1]);
336336

337337
pub.Subscribe("B");
338338
pub.SendFrame("A");
@@ -356,7 +356,7 @@ public void WelcomeMessage()
356356

357357
var subscription = pub.ReceiveFrameBytes();
358358

359-
Assert.Equal(subscription[1], (byte)'W');
359+
Assert.Equal((byte)'W', subscription[1]);
360360

361361
Assert.Equal("W", sub.ReceiveFrameString());
362362
}
@@ -377,7 +377,7 @@ public void ClearWelcomeMessage()
377377

378378
var subscription = pub.ReceiveFrameBytes();
379379

380-
Assert.Equal(subscription[1], (byte)'W');
380+
Assert.Equal((byte)'W', subscription[1]);
381381

382382
Assert.False(sub.TrySkipFrame());
383383
}

0 commit comments

Comments
 (0)