-
-
Notifications
You must be signed in to change notification settings - Fork 969
Add unit tests for task-based asynchronous API #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
7d5ccb8
2a47c9e
ba7ecbb
81b3a16
be97986
f91c5f1
8c66267
5304296
a7a9474
de9faec
5bc16c8
36b751b
362910f
c1a657a
bae6c54
48e1af3
f0a8f5f
382649b
07c1535
0030b35
2fbdb46
3547504
3506707
9f45e7f
a53f35b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| os: Visual Studio 2019 | ||
|
|
||
| init: | ||
| - netsh int ipv4 set dynamicport tcp start=1025 num=64510 | ||
|
|
||
| before_build: | ||
| - nuget restore src\Renci.SshNet.VS2019.sln | ||
|
|
||
|
|
@@ -9,6 +12,6 @@ build: | |
|
|
||
| test_script: | ||
| - cmd: >- | ||
| vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net40\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" | ||
| vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net472\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" | ||
|
|
||
| vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net35\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd first like to discuss dropping .NET 3.5 support. |
||
| vstest.console /logger:Appveyor src\Renci.SshNet.Tests\bin\Debug\net5.0\Renci.SshNet.Tests.dll /TestCaseFilter:"TestCategory!=integration&TestCategory!=LongRunning" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ public class BaseClientTest_Connected_KeepAliveInterval_NotNegativeOne : BaseCli | |
| private ConnectionInfo _connectionInfo; | ||
| private TimeSpan _keepAliveInterval; | ||
| private int _keepAliveCount; | ||
| private int _actualKeepAliveCount; | ||
|
|
||
| protected override void SetupData() | ||
| { | ||
|
|
@@ -58,6 +59,8 @@ protected override void Act() | |
|
|
||
| // allow keep-alive to be sent a few times | ||
| Thread.Sleep(195); | ||
|
|
||
| _actualKeepAliveCount = _keepAliveCount; | ||
| } | ||
|
|
||
| [TestMethod] | ||
|
|
@@ -94,7 +97,7 @@ public void IsConnectedOnSessionShouldBeInvokedOnce() | |
| [TestMethod] | ||
| public void SendMessageOnSessionShouldBeInvokedThreeTimes() | ||
| { | ||
| _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3)); | ||
| Assert.AreEqual(3, _actualKeepAliveCount); | ||
|
||
| } | ||
|
|
||
| private class MyClient : BaseClient | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,17 +51,13 @@ public void CleanUp() | |
| _remoteListener = null; | ||
| } | ||
|
|
||
| if (_channelThread != null) | ||
| { | ||
| if (_channelThread.IsAlive) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose you did this because Thread.Abort is no longer supported on .NET (Core).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
| _channelThread.Abort(); | ||
| _channelThread = null; | ||
| } | ||
| if (_channel != null) | ||
| { | ||
| _channel.Dispose(); | ||
| _channel = null; | ||
| } | ||
|
|
||
| _channelThread = null; | ||
| } | ||
|
|
||
| private void Arrange() | ||
|
|
@@ -138,10 +134,12 @@ private void Arrange() | |
| _remoteWindowSize, | ||
| _remotePacketSize); | ||
|
|
||
| ManualResetEvent isReady = new ManualResetEvent(false); | ||
|
||
| _channelThread = new Thread(() => | ||
| { | ||
| try | ||
| { | ||
| isReady.Set(); | ||
| _channel.Bind(_remoteEndpoint, _forwardedPortMock.Object); | ||
| } | ||
| catch (Exception ex) | ||
|
|
@@ -156,6 +154,7 @@ private void Arrange() | |
| _channelThread.Start(); | ||
|
|
||
| // give channel time to bind to remote endpoint | ||
| isReady.WaitOne(10000); | ||
| Thread.Sleep(100); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,14 @@ public class PipeStream_Close_BlockingWrite : TripleATestBase | |
| { | ||
| private PipeStream _pipeStream; | ||
| private Exception _writeException; | ||
| private Thread _writehread; | ||
| private Thread _writeThread; | ||
|
|
||
| protected override void Arrange() | ||
| { | ||
| _pipeStream = new PipeStream {MaxBufferLength = 3}; | ||
|
|
||
| _writehread = new Thread(() => | ||
| ManualResetEvent isArranged = new ManualResetEvent(false); | ||
|
||
| _writeThread = new Thread(() => | ||
| { | ||
| _pipeStream.WriteByte(10); | ||
| _pipeStream.WriteByte(13); | ||
|
|
@@ -27,32 +28,32 @@ protected override void Arrange() | |
| // until bytes are read or the stream is closed | ||
| try | ||
| { | ||
| isArranged.Set(); | ||
| _pipeStream.WriteByte(35); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _writeException = ex; | ||
| throw; | ||
| } | ||
| }); | ||
| _writehread.Start(); | ||
| _writeThread.Start(); | ||
|
|
||
| // ensure we've started writing | ||
| Assert.IsFalse(_writehread.Join(50)); | ||
| isArranged.WaitOne(10000); | ||
| } | ||
|
|
||
| protected override void Act() | ||
| { | ||
| _pipeStream.Close(); | ||
|
|
||
| // give write time to complete | ||
| _writehread.Join(100); | ||
| Assert.IsTrue(_writeThread.Join(10000)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void BlockingWriteShouldHaveBeenInterrupted() | ||
| { | ||
| Assert.AreEqual(ThreadState.Stopped, _writehread.ThreadState); | ||
| Assert.AreEqual(ThreadState.Stopped, _writeThread.ThreadState); | ||
| } | ||
|
|
||
| [TestMethod] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,10 @@ public void ConnectShouldHaveThrownSocketException() | |
| { | ||
| Assert.IsNotNull(_actualException); | ||
| Assert.IsNull(_actualException.InnerException); | ||
| Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode); | ||
| if (_actualException.SocketErrorCode != SocketError.TryAgain) | ||
|
||
| { | ||
| Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,10 @@ public void ConnectShouldHaveThrownSocketException() | |
| { | ||
| Assert.IsNotNull(_actualException); | ||
| Assert.IsNull(_actualException.InnerException); | ||
| Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode); | ||
| if (_actualException.SocketErrorCode != SocketError.TryAgain) | ||
|
||
| { | ||
| Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,7 +130,10 @@ public void ClosingShouldHaveFiredOnce() | |
| [TestMethod] | ||
| public void ExceptionShouldNotHaveFired() | ||
| { | ||
| Assert.AreEqual(0, _exceptionRegister.Count); | ||
| if (_exceptionRegister.Count > 0) | ||
| { | ||
| throw new Exception("ForwardedPortDynamic rased an exception: " + _exceptionRegister[0].Exception.Message, _exceptionRegister[0].Exception); | ||
| } | ||
|
||
| } | ||
|
|
||
| [TestMethod] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this resolve any issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was more of a "we open and close a lot of ports in tests and the tests are sporadically failing with connection failures, so more client-side ports can't hurt" line of reasoning.