Skip to content
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
5 changes: 3 additions & 2 deletions Tests/NetworkHelperTests/ConnectToEthernetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public void TestSingleUsage()
[TestMethod]
public void TestRetryAfterTimeout()
{
// First attempt: very short timeout so it expires
CancellationTokenSource cs1 = new(1000);
// First attempt: pre-cancelled token guarantees timeout regardless of network state
CancellationTokenSource cs1 = new();
cs1.Cancel();
var firstResult = NetworkHelper.SetupAndConnectNetwork(token: cs1.Token);

Assert.IsFalse(firstResult, "First call should have timed out");
Expand Down
23 changes: 15 additions & 8 deletions Tests/SocketTests/SocketExceptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void SocketExceptionTest3_Protocol_Address_FamilyNotSupported()
}
catch (SocketException e)
{
Assert.IsFalse(e.ErrorCode != (int)SocketError.ProtocolFamilyNotSupported && e.ErrorCode != (int)SocketError.AddressFamilyNotSupported, "Incorrect ErrorCode in SocketException "
Assert.IsFalse(e.ErrorCode != (int)SocketError.ProtocolFamilyNotSupported && e.ErrorCode != (int)SocketError.AddressFamilyNotSupported && e.ErrorCode != (int)SocketError.ProtocolNotSupported, "Incorrect ErrorCode in SocketException "
+ e.ErrorCode);
return;
}
Expand All @@ -57,16 +57,14 @@ public void SocketExceptionTest3_Protocol_Address_FamilyNotSupported()
[TestMethod]
public void SocketExceptionTest4_ProtocolNotSupported()
{

try
{
Socket socketTest = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Udp);
}
catch (SocketException e)
{
Assert.AreEqual((int)SocketError.ProtocolNotSupported, e.ErrorCode, "Incorrect ErrorCode in SocketException "
+ e.ErrorCode);
Assert.AreEqual((int)SocketError.ProtocolNotSupported, e.ErrorCode, "Incorrect ErrorCode in SocketException " + e.ErrorCode);
return;
}
throw new Exception("No SocketException thrown");
Expand Down Expand Up @@ -112,16 +110,18 @@ public void SocketExceptionTest11_AccessDenied()
public void SocketExceptionTest12_NotConnected()
{
SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
Socket socketTemp = null;

Assert.ThrowsException(typeof(SocketException), () =>
{
testSockets.Startup(0, 0);
Socket socketTemp = new Socket(AddressFamily.InterNetwork,
socketTemp = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
socketTemp.Bind(testSockets.socketServer.RemoteEndPoint);
socketTemp.Send(new byte[2]);
});

socketTemp?.Close();
testSockets.TearDown();
}

Expand All @@ -146,17 +146,24 @@ public void SocketExceptionTest13_InvalidArgument()
[TestMethod]
public void SocketExceptionTest14_AddressNotAvailable()
{
// Bind to an IP not assigned to any local interface, then connect to force address validation.
// nanoFramework's LWIP stack defers the AddressNotAvailable error to connect time, not bind time.
SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
Socket freshSocket = null;

Assert.ThrowsException(typeof(SocketException), () =>
{
int clientPort = SocketTools.nextPort;
int serverPort = SocketTools.nextPort;
int tempPort = clientPort;
int clientPort = SocketTools.nextPort;
testSockets.Startup(clientPort, serverPort);
testSockets.socketServer.Listen(1);

testSockets.socketClient.Bind(new IPEndPoint(new IPAddress(SocketTools.DottedDecimalToIp((byte)192, (byte)168, (byte)192, (byte)168)), tempPort));
freshSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
freshSocket.Bind(new IPEndPoint(new IPAddress(SocketTools.DottedDecimalToIp((byte)192, (byte)168, (byte)192, (byte)168)), SocketTools.nextPort));
freshSocket.Connect(testSockets.epServer);
});

freshSocket?.Close();
testSockets.TearDown();
}

Expand Down