Skip to content

Commit 4613059

Browse files
committed
fix to run tests on Windows OS
1 parent 2635b7a commit 4613059

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/Smdn.Net.MuninNode/Smdn.Net.MuninNode/NodeBase.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net;
88
using System.Net.Sockets;
99
using System.IO;
10+
using System.Runtime.InteropServices;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213
using NUnit.Framework;
@@ -46,9 +47,9 @@ protected override EndPoint GetLocalEndPointToBind()
4647
=> new IPEndPoint(
4748
address:
4849
Socket.OSSupportsIPv6
49-
? IPAddress.IPv6Any
50+
? RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? IPAddress.IPv6Loopback : IPAddress.IPv6Any
5051
: Socket.OSSupportsIPv4
51-
? IPAddress.Any
52+
? RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? IPAddress.Loopback : IPAddress.Any
5253
: throw new NotSupportedException(),
5354
port: 0
5455
);
@@ -272,11 +273,19 @@ async static (node, client, writer, reader, cancellationToken
272273
await writer.WriteLineAsync(".", cancellationToken);
273274
await writer.FlushAsync(cancellationToken);
274275

275-
Assert.That(
276-
await reader.ReadLineAsync(cancellationToken),
277-
Is.Null,
278-
"line #1"
279-
);
276+
try {
277+
Assert.That(
278+
await reader.ReadLineAsync(cancellationToken),
279+
Is.Null,
280+
"line #1"
281+
);
282+
}
283+
catch (IOException ex) when (
284+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
285+
ex.InnerException is SocketException
286+
) {
287+
// ignore
288+
}
280289

281290
var connected = !(
282291
client.Client.Poll(1 /*microsecs*/, SelectMode.SelectRead) &&

0 commit comments

Comments
 (0)