Skip to content

Commit 66ba99b

Browse files
committed
Fixes from code review
1 parent 631e540 commit 66ba99b

10 files changed

Lines changed: 154 additions & 64 deletions

File tree

‎Tests/IPAddressTests/IPAddressTests.nfproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@
6262
<ProjectConfigurationsDeclaredAsItems />
6363
</ProjectCapabilities>
6464
</ProjectExtensions>
65-
</Project>
65+
</Project>

‎Tests/NetworkHelperTests/NetworkHelperTests.nfproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@
7171
<ProjectConfigurationsDeclaredAsItems />
7272
</ProjectCapabilities>
7373
</ProjectExtensions>
74-
</Project>
74+
</Project>

‎Tests/NetworkTestCompanion/Program.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using NetworkTestCompanion;
88

99
const int DefaultControlPort = 11000;
10-
int[] WellKnownTcpPorts = [DefaultControlPort, 7, 8, 9, 10, 80, 8080, 7010, 7011, 7012, 7013, 7014];
10+
int[] WellKnownTcpPorts = [DefaultControlPort, 7, 8, 9, 10, 80, 8080, 7010, 7011, 7012, 7013, 7014, 7015];
1111
int[] WellKnownUdpPorts = [7, 8, 9];
1212

1313
// Argument parsing

‎Tests/SocketTests/SocketTests.nfproj‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,25 @@
6262
<ProjectReference Include="..\..\nanoFramework.System.Net\System.Net.nfproj" />
6363
</ItemGroup>
6464
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
65-
6665
<!--
6766
Generate TestConfiguration.cs from the shared .runsettings file so that
6867
CompanionIP and CompanionControlPort only need to be set in one place.
6968
The file is NOT committed to source; a fresh checkout receives it when
7069
the GenerateTestConfiguration target runs before the first build.
7170
-->
7271
<Target Name="GenerateTestConfiguration" BeforeTargets="BeforeBuild">
73-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
74-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
72+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
7573
<Output TaskParameter="Result" ItemName="_CompanionIPItems" />
7674
</XmlPeek>
77-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
78-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
75+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
7976
<Output TaskParameter="Result" ItemName="_CompanionPortItems" />
8077
</XmlPeek>
81-
8278
<PropertyGroup>
8379
<_CompanionIP>@(_CompanionIPItems)</_CompanionIP>
8480
<_CompanionPort>@(_CompanionPortItems)</_CompanionPort>
8581
<_CompanionIP Condition="'$(_CompanionIP)' == ''">127.0.0.1</_CompanionIP>
8682
<_CompanionPort Condition="'$(_CompanionPort)' == ''">11000</_CompanionPort>
8783
</PropertyGroup>
88-
8984
<ItemGroup>
9085
<_TestConfigLines Include="// Auto-generated from .runsettings - do not edit directly." />
9186
<_TestConfigLines Include="//" />
@@ -101,19 +96,13 @@
10196
<_TestConfigLines Include="%20%20%20%20}" />
10297
<_TestConfigLines Include="}" />
10398
</ItemGroup>
104-
105-
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs"
106-
Lines="@(_TestConfigLines)"
107-
Overwrite="true"
108-
Encoding="UTF-8" />
109-
99+
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs" Lines="@(_TestConfigLines)" Overwrite="true" Encoding="UTF-8" />
110100
<Message Text="Generated TestConfiguration.cs: CompanionIP=$(_CompanionIP) CompanionControlPort=$(_CompanionPort)" Importance="normal" />
111101
</Target>
112-
113102
<!-- MANUAL UPDATE HERE -->
114103
<ProjectExtensions>
115104
<ProjectCapabilities>
116105
<ProjectConfigurationsDeclaredAsItems />
117106
</ProjectCapabilities>
118107
</ProjectExtensions>
119-
</Project>
108+
</Project>

‎Tests/SslStreamTests/SslStreamTests.nfproj‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Label="Globals">
44
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
@@ -65,28 +65,23 @@
6565
<ProjectReference Include="..\..\nanoFramework.System.Net\System.Net.nfproj" />
6666
</ItemGroup>
6767
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
68-
6968
<!--
7069
Generate TestConfiguration.cs from the shared .runsettings file so that
7170
CompanionIP and CompanionControlPort only need to be set in one place.
7271
-->
7372
<Target Name="GenerateTestConfiguration" BeforeTargets="BeforeBuild">
74-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
75-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
73+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
7674
<Output TaskParameter="Result" ItemName="_CompanionIPItems" />
7775
</XmlPeek>
78-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
79-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
76+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
8077
<Output TaskParameter="Result" ItemName="_CompanionPortItems" />
8178
</XmlPeek>
82-
8379
<PropertyGroup>
8480
<_CompanionIP>@(_CompanionIPItems)</_CompanionIP>
8581
<_CompanionPort>@(_CompanionPortItems)</_CompanionPort>
8682
<_CompanionIP Condition="'$(_CompanionIP)' == ''">127.0.0.1</_CompanionIP>
8783
<_CompanionPort Condition="'$(_CompanionPort)' == ''">11000</_CompanionPort>
8884
</PropertyGroup>
89-
9085
<ItemGroup>
9186
<_TestConfigLines Include="// Auto-generated from .runsettings - do not edit directly." />
9287
<_TestConfigLines Include="//" />
@@ -102,19 +97,13 @@
10297
<_TestConfigLines Include="%20%20%20%20}" />
10398
<_TestConfigLines Include="}" />
10499
</ItemGroup>
105-
106-
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs"
107-
Lines="@(_TestConfigLines)"
108-
Overwrite="true"
109-
Encoding="UTF-8" />
110-
100+
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs" Lines="@(_TestConfigLines)" Overwrite="true" Encoding="UTF-8" />
111101
<Message Text="Generated TestConfiguration.cs: CompanionIP=$(_CompanionIP) CompanionControlPort=$(_CompanionPort)" Importance="normal" />
112102
</Target>
113-
114103
<!-- MANUAL UPDATE HERE -->
115104
<ProjectExtensions>
116105
<ProjectCapabilities>
117106
<ProjectConfigurationsDeclaredAsItems />
118107
</ProjectCapabilities>
119108
</ProjectExtensions>
120-
</Project>
109+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": 1,
3+
"dependencies": {
4+
".NETnanoFramework,Version=v1.0": {
5+
"nanoFramework.CoreLibrary": {
6+
"type": "Direct",
7+
"requested": "[1.17.11, 1.17.11]",
8+
"resolved": "1.17.11",
9+
"contentHash": "HezzAc0o2XrSGf85xSeD/6xsO6ohF9hX6/iMQ1IZS6Zw6umr4WfAN2Jv0BrPxkaYwzEegJxxZujkHoUIAqtOMw=="
10+
},
11+
"nanoFramework.System.IO.Streams": {
12+
"type": "Direct",
13+
"requested": "[1.1.96, 1.1.96]",
14+
"resolved": "1.1.96",
15+
"contentHash": "kJSy4EJwChO4Vq3vGWP9gNRPFDnTsDU5HxzeI7NDO+RjbDsx7B8EhKymoeTPLJCxQq8y/0P1KG2XCxGpggW+fw=="
16+
},
17+
"nanoFramework.System.Text": {
18+
"type": "Direct",
19+
"requested": "[1.3.42, 1.3.42]",
20+
"resolved": "1.3.42",
21+
"contentHash": "68HPjhersNpssbmEMUHdMw3073MHfGTfrkbRk9eILKbNPFfPFck7m4y9BlAi6DaguUJaeKxgyIojXF3SQrF8/A=="
22+
},
23+
"nanoFramework.System.Threading": {
24+
"type": "Direct",
25+
"requested": "[1.1.52, 1.1.52]",
26+
"resolved": "1.1.52",
27+
"contentHash": "kv+US/+7QKV1iT/snxBh032vwZ+3krJ4vujlSsvmS2nNj/nK64R3bq/ST3bCFquxHDD0mog8irtCBCsFazr4kA=="
28+
},
29+
"nanoFramework.TestFramework": {
30+
"type": "Direct",
31+
"requested": "[3.0.80, 3.0.80]",
32+
"resolved": "3.0.80",
33+
"contentHash": "o2ymxAz6TC6VguKqN6rrGB/L4sVAIJVEut87Hq8MvwEe6P/7JwzX+VB4vKJxEmihCSJs7Z3Yo9Rb8HgIEo8DMg=="
34+
}
35+
}
36+
}
37+
}

‎Tests/SslStreamTests_WiFi/SslServerTests.cs‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,20 @@ public void DeviceAsServer_TlsEchoRoundTrip()
156156
AuthenticateAsServerLogged(sslStream, serverCert);
157157
OutputHelper.WriteLine("TLS server handshake succeeded");
158158

159-
byte[] buffer = new byte[1024];
160-
int bytesRead = sslStream.Read(buffer, 0, buffer.Length);
159+
byte[] buffer = new byte[testData.Length];
160+
int bytesRead = 0;
161+
162+
while (bytesRead < testData.Length)
163+
{
164+
int n = sslStream.Read(buffer, bytesRead, testData.Length - bytesRead);
165+
if (n == 0)
166+
{
167+
break;
168+
}
169+
170+
bytesRead += n;
171+
}
161172

162-
Assert.IsTrue(bytesRead > 0, "Should have received data from companion");
163173
Assert.AreEqual(testData.Length, bytesRead, "Should receive exact bytes sent by companion");
164174

165175
for (int i = 0; i < bytesRead; i++)
@@ -212,8 +222,19 @@ public void DeviceAsClient_TlsEchoRoundTrip()
212222
byte[] sent = Encoding.UTF8.GetBytes("Hello TLS echo from device!");
213223
sslStream.Write(sent, 0, sent.Length);
214224

215-
byte[] buffer = new byte[1024];
216-
int bytesRead = sslStream.Read(buffer, 0, buffer.Length);
225+
byte[] buffer = new byte[sent.Length];
226+
int bytesRead = 0;
227+
228+
while (bytesRead < sent.Length)
229+
{
230+
int n = sslStream.Read(buffer, bytesRead, sent.Length - bytesRead);
231+
if (n == 0)
232+
{
233+
break;
234+
}
235+
236+
bytesRead += n;
237+
}
217238

218239
Assert.AreEqual(sent.Length, bytesRead, "Echo response length should match sent data");
219240

@@ -381,9 +402,10 @@ public void DeviceAsClient_WriteAfterPeerClose_ShouldThrow()
381402
// send() after close usually succeeds locally (bytes are just queued in the local
382403
// send buffer) and the failure only surfaces on a later write, once the RST has
383404
// been received or the send buffer can't drain. So write repeatedly - each call
384-
// bounded by SendTimeout - until one fails. The underlying failure can surface as
385-
// either a native SocketException or the managed IOException guard, so it's
386-
// normalized to IOException before being re-thrown for the assertion.
405+
// bounded by SendTimeout - until one fails. Only the two documented failure modes
406+
// (native SocketException, or the managed IOException guard) are normalized to
407+
// IOException; any other exception type is left to propagate so an unrelated bug
408+
// fails the test loudly instead of being reported as the expected outcome.
387409
byte[] payload = Encoding.UTF8.GetBytes("this should fail");
388410
const int maxAttempts = 5;
389411

@@ -399,7 +421,12 @@ public void DeviceAsClient_WriteAfterPeerClose_ShouldThrow()
399421
OutputHelper.WriteLine($"Attempt {attempt}/{maxAttempts}: Write({payload.Length} bytes) returned without error on a dead connection");
400422
Thread.Sleep(500);
401423
}
402-
catch (Exception ex)
424+
catch (IOException)
425+
{
426+
OutputHelper.WriteLine($"Attempt {attempt}/{maxAttempts}: Write failed as expected: IOException");
427+
throw;
428+
}
429+
catch (SocketException ex)
403430
{
404431
OutputHelper.WriteLine($"Attempt {attempt}/{maxAttempts}: Write failed as expected: {ex.GetType().Name}: {ex.Message}");
405432
throw new IOException("Write failed on dead connection", ex);

‎Tests/SslStreamTests_WiFi/SslStreamTests_WiFi.nfproj‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Label="Globals">
44
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
@@ -51,12 +51,15 @@
5151
<Reference Include="nanoFramework.Runtime.Events, Version=1.11.37.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
5252
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.11.37\lib\nanoFramework.Runtime.Events.dll</HintPath>
5353
</Reference>
54-
<Reference Include="System.Device.Wifi, Version=1.5.147.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
55-
<HintPath>..\..\packages\nanoFramework.System.Device.Wifi.1.5.147\lib\System.Device.Wifi.dll</HintPath>
54+
<Reference Include="System.Device.Wifi, Version=1.5.149.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
55+
<HintPath>..\..\packages\nanoFramework.System.Device.Wifi.1.5.149\lib\System.Device.Wifi.dll</HintPath>
5656
</Reference>
5757
<Reference Include="System.IO.Streams, Version=1.1.96.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
5858
<HintPath>..\..\packages\nanoFramework.System.IO.Streams.1.1.96\lib\System.IO.Streams.dll</HintPath>
5959
</Reference>
60+
<Reference Include="System.Net, Version=1.11.60.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
61+
<HintPath>..\..\packages\nanoFramework.System.Net.1.11.60\lib\System.Net.dll</HintPath>
62+
</Reference>
6063
<Reference Include="System.Threading, Version=1.1.52.34401, Culture=neutral, PublicKeyToken=c07d481e9758c731">
6164
<HintPath>..\..\packages\nanoFramework.System.Threading.1.1.52\lib\System.Threading.dll</HintPath>
6265
</Reference>
@@ -68,28 +71,23 @@
6871
<ProjectReference Include="..\..\nanoFramework.System.Net\System.Net.nfproj" />
6972
</ItemGroup>
7073
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
71-
7274
<!--
7375
Generate TestConfiguration.cs from the shared .runsettings file so that
7476
CompanionIP and CompanionControlPort only need to be set in one place.
7577
-->
7678
<Target Name="GenerateTestConfiguration" BeforeTargets="BeforeBuild">
77-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
78-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
79+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionIP']/@value">
7980
<Output TaskParameter="Result" ItemName="_CompanionIPItems" />
8081
</XmlPeek>
81-
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings"
82-
Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
82+
<XmlPeek XmlInputPath="$(MSBuildThisFileDirectory)..\..\.runsettings" Query="/RunSettings/TestRunParameters/Parameter[@name='CompanionControlPort']/@value">
8383
<Output TaskParameter="Result" ItemName="_CompanionPortItems" />
8484
</XmlPeek>
85-
8685
<PropertyGroup>
8786
<_CompanionIP>@(_CompanionIPItems)</_CompanionIP>
8887
<_CompanionPort>@(_CompanionPortItems)</_CompanionPort>
8988
<_CompanionIP Condition="'$(_CompanionIP)' == ''">127.0.0.1</_CompanionIP>
9089
<_CompanionPort Condition="'$(_CompanionPort)' == ''">11000</_CompanionPort>
9190
</PropertyGroup>
92-
9391
<ItemGroup>
9492
<_TestConfigLines Include="// Auto-generated from .runsettings - do not edit directly." />
9593
<_TestConfigLines Include="//" />
@@ -105,19 +103,13 @@
105103
<_TestConfigLines Include="%20%20%20%20}" />
106104
<_TestConfigLines Include="}" />
107105
</ItemGroup>
108-
109-
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs"
110-
Lines="@(_TestConfigLines)"
111-
Overwrite="true"
112-
Encoding="UTF-8" />
113-
106+
<WriteLinesToFile File="$(MSBuildThisFileDirectory)TestConfiguration.cs" Lines="@(_TestConfigLines)" Overwrite="true" Encoding="UTF-8" />
114107
<Message Text="Generated TestConfiguration.cs: CompanionIP=$(_CompanionIP) CompanionControlPort=$(_CompanionPort)" Importance="normal" />
115108
</Target>
116-
117109
<!-- MANUAL UPDATE HERE -->
118110
<ProjectExtensions>
119111
<ProjectCapabilities>
120112
<ProjectConfigurationsDeclaredAsItems />
121113
</ProjectCapabilities>
122114
</ProjectExtensions>
123-
</Project>
115+
</Project>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.17.11" targetFramework="netnano1.0" />
44
<package id="nanoFramework.Runtime.Events" version="1.11.37" targetFramework="netnano1.0" />
5-
<package id="nanoFramework.System.Device.Wifi" version="1.5.147" targetFramework="netnano1.0" />
5+
<package id="nanoFramework.System.Device.Wifi" version="1.5.149" targetFramework="netnano1.0" />
66
<package id="nanoFramework.System.IO.Streams" version="1.1.96" targetFramework="netnano1.0" />
7+
<package id="nanoFramework.System.Net" version="1.11.60" targetFramework="netnano1.0" />
78
<package id="nanoFramework.System.Text" version="1.3.42" targetFramework="netnano1.0" />
89
<package id="nanoFramework.System.Threading" version="1.1.52" targetFramework="netnano1.0" />
910
<package id="nanoFramework.TestFramework" version="3.0.80" targetFramework="netnano1.0" developmentDependency="true" />
10-
</packages>
11+
</packages>

0 commit comments

Comments
 (0)