From cb947388ad0170a56fec76cb90cf3c1b99a62d85 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 01:55:10 +0300 Subject: [PATCH 1/6] Run tests both on Windows & Linux --- appveyor.yml | 19 +++++++++++++++---- .../Renci.SshNet.Tests.csproj | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c9bb51683..e4aedd756 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,14 +1,25 @@ -os: Visual Studio 2022 +image: + - Visual Studio 2022 + - Ubuntu before_build: - - nuget restore src\Renci.SshNet.sln +- cmd: >- + nuget restore src\Renci.SshNet.sln +- sh: >- + dotnet restore src/Renci.SshNet.sln build: project: src\Renci.SshNet.sln verbosity: minimal +configuration: Release + test_script: - cmd: >- - vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame + vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Release\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame - vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net7.0\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame + dotnet test src\Renci.SshNet.Tests\bin\Release\net7.0\Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + +- sh: >- + dotnet test src/Renci.SshNet.Tests/bin/Release/net7.0/Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index aa9d79a2a..6a3c424c6 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -38,6 +38,7 @@ + From 9c6978aa3e8198a00e22da0a2186114e590da1b1 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 02:29:59 +0300 Subject: [PATCH 2/6] On Linux unresolved host can result in TryAgain socket error The name of the host could not be resolved. Try again later. --- .../Classes/SftpClientTest.ConnectAsync.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs index df7a8f0b6..88ab436db 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.ConnectAsync.cs @@ -21,7 +21,7 @@ public async Task ConnectAsync_HostNameInvalid_ShouldThrowSocketExceptionWithErr } catch (SocketException ex) { - Assert.AreEqual(SocketError.HostNotFound, ex.SocketErrorCode); + Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain, $"Socket error is {ex.SocketErrorCode}"); } } @@ -39,8 +39,8 @@ public async Task ConnectAsync_ProxyHostNameInvalid_ShouldThrowSocketExceptionWi } catch (SocketException ex) { - Assert.AreEqual(SocketError.HostNotFound, ex.SocketErrorCode); + Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain, $"Socket error is {ex.SocketErrorCode}"); } } } -} \ No newline at end of file +} From 47eb27b8edc50ab9b44079ff78500578520e5349 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 02:46:46 +0300 Subject: [PATCH 3/6] Ports <= 1024 are priveleged under Linux and require root for tests --- .../Classes/Connection/DirectConnectorTestBase.cs | 2 +- .../HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs | 2 +- .../HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs | 2 +- .../Classes/Connection/Socks4ConnectorTestBase.cs | 2 +- .../Socks4ConnectorTest_Connect_ConnectionSucceeded.cs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs b/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs index d1989c3de..7eb9040e9 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs @@ -36,7 +36,7 @@ protected sealed override void Arrange() protected ConnectionInfo CreateConnectionInfo(string hostName) { return new ConnectionInfo(hostName, - 777, + 1027, "user", new KeyboardInteractiveAuthenticationMethod("user")); } diff --git a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs index 98ffde6aa..6808bfb50 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs @@ -36,7 +36,7 @@ protected override void SetupData() var random = new Random(); _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(), - 777, + 1026, "user", ProxyTypes.Http, IPAddress.Loopback.ToString(), diff --git a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs index bec205f1a..38f65634c 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs @@ -32,7 +32,7 @@ protected override void SetupData() var random = new Random(); _connectionInfo = new ConnectionInfo(IPAddress.Loopback.ToString(), - 777, + 1028, "user", ProxyTypes.Http, IPAddress.Loopback.ToString(), diff --git a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs index 0c3497f12..d8dbe8871 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs @@ -38,7 +38,7 @@ protected sealed override void Arrange() protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword) { return new ConnectionInfo(IPAddress.Loopback.ToString(), - 777, + 1025, "user", ProxyTypes.Socks4, IPAddress.Loopback.ToString(), diff --git a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs index 5aabb8164..7edde74c5 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs @@ -103,8 +103,8 @@ public void ProxyShouldHaveReceivedExpectedSocksRequest() // CONNECT request 0x01, // Destination port - 0x03, - 0x09, + 0x04, + 0x01, // Destination address (IPv4) 0x7f, 0x00, From c06e38f490ea75f7f777d1e69a5f5ef720f6c500 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 10:50:38 +0300 Subject: [PATCH 4/6] More reliable timing in semaphore test --- src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs index 17d5e72f2..94201a9bd 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs @@ -78,7 +78,7 @@ public void WaitTest() watch.Stop(); - Assert.IsTrue(watch.ElapsedMilliseconds > 200); + Assert.IsTrue(watch.ElapsedMilliseconds >= sleepTime - 5); Assert.IsTrue(watch.ElapsedMilliseconds < 250); } From dd0ce17eb3b9eefbc3f30434b5c42204264943dd Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 10:50:51 +0300 Subject: [PATCH 5/6] Run both Debug and Release tests --- appveyor.yml | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e4aedd756..883cb4cdd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,14 +12,35 @@ build: project: src\Renci.SshNet.sln verbosity: minimal -configuration: Release +configuration: + - Debug + - Release -test_script: -- cmd: >- - vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Release\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame +for: +- + matrix: + only: + - configuration: Debug + + test_script: + - cmd: >- + vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame - dotnet test src\Renci.SshNet.Tests\bin\Release\net7.0\Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + dotnet test src\Renci.SshNet.Tests\bin\Debug\net7.0\Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame -- sh: >- - dotnet test src/Renci.SshNet.Tests/bin/Release/net7.0/Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + - sh: >- + dotnet test src/Renci.SshNet.Tests/bin/Debug/net7.0/Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + +- + matrix: + only: + - configuration: Release + + test_script: + - cmd: >- + vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Release\net462\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration" --blame + + dotnet test src\Renci.SshNet.Tests\bin\Release\net7.0\Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame + - sh: >- + dotnet test src/Renci.SshNet.Tests/bin/Release/net7.0/Renci.SshNet.Tests.dll --logger Appveyor --filter "TestCategory!=integration" --blame \ No newline at end of file From 24bdde2547d80647fa41c3bb696e2875858c411b Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Wed, 27 Sep 2023 15:26:07 +0300 Subject: [PATCH 6/6] Play with timeout as on Linux we get connection refused --- .../DirectConnectorTest_Connect_TimeoutConnectingToServer.cs | 2 +- .../HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs | 2 +- .../Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs | 2 +- .../Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs b/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs index 661b286ae..64e8bfe13 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs @@ -27,7 +27,7 @@ protected override void SetupData() var random = new Random(); _connectionInfo = CreateConnectionInfo(IPAddress.Loopback.ToString()); - _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200)); + _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(0, 5)); _stopWatch = new Stopwatch(); _actualException = null; diff --git a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs index bb8041c89..815543700 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs @@ -36,7 +36,7 @@ protected override void SetupData() "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")) { - Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200)) + Timeout = TimeSpan.FromMilliseconds(random.Next(0, 5)) }; _stopWatch = new Stopwatch(); _actualException = null; diff --git a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs index d7ad42157..a76d07482 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs @@ -23,7 +23,7 @@ protected override void SetupData() var random = new Random(); _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd"); - _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200)); + _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(0, 5)); _stopWatch = new Stopwatch(); _clientSocket = SocketFactory.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _actualException = null; diff --git a/src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs b/src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs index 720c24ff9..3ebe4e01f 100644 --- a/src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs +++ b/src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs @@ -26,7 +26,7 @@ protected override void SetupData() var random = new Random(); _connectionInfo = CreateConnectionInfo("proxyUser", "proxyPwd"); - _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200)); + _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(0, 5)); _stopWatch = new Stopwatch(); _actualException = null;