Skip to content
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

Use CollectionAssert in ListDirectory tests #1166

Merged
merged 4 commits into from
Nov 13, 2023

Conversation

Rob-Hague
Copy link
Collaborator

These tests were failing for me because the files were coming in in a different order

Plus, CollectionAssert.AreEquivalent gives a nice failure message

@WojciechNagorski
Copy link
Collaborator

Can you tell me in what order you got the results?
I don't have full knowledge about the project yet, but perhaps the problem is not checking, but a random order.

@Rob-Hague
Copy link
Collaborator Author

 Create_directory_with_contents_and_list_it
   Source: SftpClientTests.cs line 21
   Duration: 172 ms

  Message: 
Assert.AreEqual failed. Expected:</home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
>. Actual:</home/sshnet/sshnet-test/test-file.txt True False
/home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
>. 

Same for Create_directory_with_contents_and_list_it_async

I have not looked at the implementation, but I would not expect it to do any sorting - the user can sort the files how they like.

@WojciechNagorski
Copy link
Collaborator

It needs to be checked. I don't know if it shouldn't be deterministic.

@Rob-Hague
Copy link
Collaborator Author

So the directory listing functionality is the sending of a SSH_FXP_READDIR packet. I do not see anything relating to sort order in the RFC and the library implementation is reading out the filenames as they are returned (into an array, and then a list).

private IEnumerable<ISftpFile> InternalListDirectory(string path, Action<int> listCallback)

public KeyValuePair<string, SftpFileAttributes>[] RequestReadDir(byte[] handle)

protected override void LoadData()
{
base.LoadData();
Count = ReadUInt32();
Files = new KeyValuePair<string, SftpFileAttributes>[Count];
for (var i = 0; i < Count; i++)
{
var fileName = ReadString(Encoding);
if (SupportsLongName(ProtocolVersion))
{
_ = ReadString(Encoding); // skip longname
}
Files[i] = new KeyValuePair<string, SftpFileAttributes>(fileName, ReadAttributes());
}
}

It looks fine to me.

@Rob-Hague
Copy link
Collaborator Author

Also seen in #1220

  Failed Create_directory_with_contents_and_list_it [128 ms]
  Error Message:
   Assert.AreEqual failed. Expected:</home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
>. Actual:</home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
/home/sshnet/sshnet-test/. False True
>. 
  Stack Trace:
     at Renci.SshNet.IntegrationTests.SftpClientTests.Create_directory_with_contents_and_list_it() in /home/appveyor/projects/ssh-net/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs:line 48
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

@WojciechNagorski
Copy link
Collaborator

It is strange, but I've just got the same error ;)
image

@WojciechNagorski WojciechNagorski merged commit 823bc1b into sshnet:develop Nov 13, 2023
@Rob-Hague Rob-Hague deleted the collectionassert branch November 13, 2023 07:31
@WojciechNagorski WojciechNagorski added this to the 2023.0.1 milestone Nov 16, 2023
@WojciechNagorski
Copy link
Collaborator

The 2023.0.1 version has been released to Nuget: https://www.nuget.org/packages/SSH.NET/2023.0.1

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