Add unit tests for task-based asynchronous API by IgorMilavec · Pull Request #906 · sshnet/SSH.NET · GitHub
Skip to content

Add unit tests for task-based asynchronous API - #906

Merged
drieseng merged 25 commits into
sshnet:developfrom
IgorMilavec:TAP_UnitTests
Feb 15, 2022
Merged

Add unit tests for task-based asynchronous API#906
drieseng merged 25 commits into
sshnet:developfrom
IgorMilavec:TAP_UnitTests

Conversation

@IgorMilavec

Copy link
Copy Markdown
Collaborator

I have created some unit tests for async API as a basis for discussion.
@drieseng can you please have a look if I'm kicking in the right direction?

Basically I plan to duplicate these tests:

  • SftpFileStreamTest_Ctor_* -> SftpFileStreamTest_OpenAsync_*
  • SftpFileStreamTest_Read_* -> SftpFileStreamTest_ReadAsync_*
  • SftpClientTest.* -> SftpClientTest.*Async
    Have I left out any major surface area?

I have removed unsupported targets from the Tests project. I have tried to list all the relevant (and supported) targets for each VS version. I've left net35 in as it is the last one running on 2.0 runtime.

@IgorMilavec

Copy link
Copy Markdown
Collaborator Author

@zybexXL

zybexXL commented Dec 17, 2021

Copy link
Copy Markdown
Contributor

I'm also seeing AppVeyor failing a lot due to port exhaustion - I mentioned this before on #877 (comment)

@zybexXL

zybexXL commented Dec 17, 2021

Copy link
Copy Markdown
Contributor

Still failing on AppVeyor, seems to be a different issue:

Test method Renci.SshNet.Tests.Classes.BaseClientTest_Connected_KeepAliveInterval_NotNegativeOne.SendMessageOnSessionShouldBeInvokedThreeTimes threw exception: 
Moq.MockException: 
Expected invocation on the mock exactly 3 times, but was 4 times: p => p.TrySendMessage(It.IsAny<IgnoreMessage>())

@IgorMilavec

Copy link
Copy Markdown
Collaborator Author

Lots o' issues. :) That is the last non-sporadic one, hopefully it is fixed now...

@IgorMilavec
IgorMilavec marked this pull request as ready for review December 22, 2021 18:19
@IgorMilavec

Copy link
Copy Markdown
Collaborator Author

@drieseng, can you please have a look a this? In addition to adding coverage it also fixes a lot of transient errors, which blocks a lot of other PRs.

@drieseng drieseng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this PR looks great.
I indicated a few changes that I'd like to move out of this PR.
In general, please try to have smaller PRs.
PS. I happen to get carried away myself, so don't hesitate to remind me of this as well (and reject my PRs for the same reason).

public void SendMessageOnSessionShouldBeInvokedThreeTimes()
{
_sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3));
Assert.AreEqual(3, _actualKeepAliveCount);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you prefer this over verifying the mock?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the only way I found to stop this test failing sporadically for me. Let me remove non-Async changes from the PR and then we'll disuss, OK?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I flagged some other changes that you can keep in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and .... THANKS!

Comment thread appveyor.yml Outdated
os: Visual Studio 2019

init:
- netsh int ipv4 set dynamicport tcp start=1025 num=64510

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread appveyor.yml
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" No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd first like to discuss dropping .NET 3.5 support.
Perhaps we'll have a final release supporting the legacy frameworks.
As I said, let's discuss this first.


if (_channelThread != null)
{
if (_channelThread.IsAlive)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

_remoteWindowSize,
_remotePacketSize);

ManualResetEvent isReady = new ManualResetEvent(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.

_pipeStream = new PipeStream {MaxBufferLength = 3};

_writehread = new Thread(() =>
ManualResetEvent isArranged = new ManualResetEvent(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.
Let's separate this and similar changes out.

Assert.IsNotNull(_actualException);
Assert.IsNull(_actualException.InnerException);
Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode);
if (_actualException.SocketErrorCode != SocketError.TryAgain)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.

Assert.IsNotNull(_actualException);
Assert.IsNull(_actualException.InnerException);
Assert.AreEqual(SocketError.HostNotFound, _actualException.SocketErrorCode);
if (_actualException.SocketErrorCode != SocketError.TryAgain)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.

}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.ConnectionAborted)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this resolves an issue, but I always prefer to see the issue before a fix is applied for it.

This was referenced Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants