Skip to content

Commit 1f36ea1

Browse files
Christoph BauerChristoph Bauer
authored andcommitted
Warnings fixed
1 parent 598bb01 commit 1f36ea1

19 files changed

+60
-48
lines changed

src/NetMQ.Tests/ClientServer.cs

Lines changed: 2 additions & 2 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();

src/NetMQ.Tests/NetMQPollerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void AddTwoSocketAfterRemoving()
319319

320320

321321
[Fact]
322-
public void RemoveSocket()
322+
public async Task RemoveSocket()
323323
{
324324
using (var router1 = new RouterSocket())
325325
using (var router2 = new RouterSocket())
@@ -396,8 +396,8 @@ public void RemoveSocket()
396396

397397
poller.Stop();
398398
// await the pollerTask, 1ms should suffice
399-
pollerTask.Wait(1);
400-
Assert.True(pollerTask.IsCompleted);
399+
var completedTask = await Task.WhenAny(pollerTask, Task.Delay(1));
400+
Assert.Equal(pollerTask, completedTask);
401401
}
402402
}
403403

src/NetMQ.Tests/NetMQQueueTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void EnqueueDequeue()
2424
}
2525

2626
[Fact]
27-
public void EnqueueShouldNotBlockWhenCapacityIsZero()
27+
public async Task EnqueueShouldNotBlockWhenCapacityIsZero()
2828
{
2929
using (var mockSocket = new PairSocket())
3030
using (var queue = new NetMQQueue<int>())
@@ -39,8 +39,8 @@ public void EnqueueShouldNotBlockWhenCapacityIsZero()
3939
}
4040
});
4141

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

src/NetMQ.Tests/PgmTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void TwoPublishers()
187187
}
188188

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

@@ -230,8 +230,8 @@ public void Sending1000Messages()
230230
}
231231
});
232232

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

236236
Assert.Equal(1000, count);
237237
}
@@ -266,7 +266,7 @@ public void LargeMessage()
266266
[Theory(Skip = "Requires MSMQ for PGM sockets")]
267267
[InlineData("pgm://239.0.0.1:1000")]
268268
[InlineData("tcp://localhost:60000")]
269-
public void SubscriberCleanupOnUnbind(string address)
269+
public async Task SubscriberCleanupOnUnbind(string address)
270270
{
271271
for (var i = 0; i < 10; i++)
272272
{
@@ -290,8 +290,8 @@ public void SubscriberCleanupOnUnbind(string address)
290290
// var duration = DateTime.Now - time;
291291

292292
monitor.Stop();
293-
294-
monitorTask.Wait();
293+
294+
await monitorTask;
295295
}
296296
}
297297
}

src/NetMQ.Tests/RadioDish.cs

Lines changed: 3 additions & 2 deletions
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();
@@ -56,7 +57,7 @@ public async void TestAsync()
5657
int port = radio.BindRandomPort("tcp://*");
5758
dish.Connect($"tcp://127.0.0.1:{port}");
5859

59-
Thread.Sleep(100);
60+
await Task.Delay(100);
6061

6162
await radio.SendAsync("1", "HELLO");
6263
await radio.SendAsync("2", "HELLO");

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void LargeMessage()
9292
}
9393

9494
[Fact]
95-
public void ReceiveMessageWithTimeout()
95+
public async Task ReceiveMessageWithTimeout()
9696
{
9797
{
9898
var pubSync = new AutoResetEvent(false);
@@ -134,7 +134,7 @@ public void ReceiveMessageWithTimeout()
134134
t1.Start();
135135
t2.Start();
136136

137-
Task.WaitAll(t1, t2);
137+
await Task.WhenAll(t1, t2);
138138
}
139139
}
140140

src/NetMQ/Core/Address.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
1818
along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21+
using System.Diagnostics;
2122
using System.Net;
2223

2324
namespace NetMQ.Core
@@ -102,7 +103,8 @@ public Address(EndPoint endpoint)
102103
return;
103104
}
104105

105-
AddressString = endpoint.ToString();
106+
Debug.Assert(endpoint != null);
107+
AddressString = endpoint.ToString()!;
106108
}
107109

108110

@@ -112,9 +114,9 @@ public override string ToString()
112114
{
113115
switch (Protocol)
114116
{
115-
case TcpProtocol: return Resolved.ToString();
116-
case IpcProtocol: return Resolved.ToString();
117-
case PgmProtocol: return Resolved.ToString();
117+
case TcpProtocol: return Resolved!.ToString()!;
118+
case IpcProtocol: return Resolved!.ToString()!;
119+
case PgmProtocol: return Resolved!.ToString()!;
118120
}
119121
}
120122

@@ -123,7 +125,7 @@ public override string ToString()
123125
return Protocol + "://" + AddressString;
124126
}
125127

126-
return base.ToString();
128+
return base.ToString()!;
127129
}
128130

129131
public string Protocol { get; }

src/NetMQ/Core/Transports/ByteArraySegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public static explicit operator byte[](ByteArraySegment buffer)
413413
/// and has the same Offset property value
414414
/// and it's buffer points to the SAME byte-array as the otherObject does.
415415
/// </remarks>
416-
public override bool Equals(object otherObject)
416+
public override bool Equals(object? otherObject)
417417
{
418418
var byteArraySegment = otherObject as ByteArraySegment;
419419
if (byteArraySegment != null)

src/NetMQ/Core/Transports/Tcp/TcpListener.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,16 @@ private void Close()
275275
if (m_handle == null)
276276
return;
277277

278-
Assumes.NotNull(m_endpoint);
279-
280278
try
281279
{
282280
m_handle.Dispose();
283-
m_socket.EventClosed(m_endpoint, m_handle);
281+
if (m_endpoint is not null)
282+
m_socket.EventClosed(m_endpoint, m_handle);
284283
}
285284
catch (SocketException ex)
286285
{
287-
m_socket.EventCloseFailed(m_endpoint, ex.SocketErrorCode.ToErrorCode());
286+
if (m_endpoint is not null)
287+
m_socket.EventCloseFailed(m_endpoint, ex.SocketErrorCode.ToErrorCode());
288288
}
289289

290290
m_handle = null;

0 commit comments

Comments
 (0)