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

fix flaky Sftp_BeginUploadFile test #1402

Merged
merged 4 commits into from
May 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/Renci.SshNet.IntegrationTests/SftpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ public void Sftp_BeginUploadFile()
using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(content)))
{
IAsyncResult asyncResultCallback = null;
var callbackCalled = new ManualResetEvent(false);
mus65 marked this conversation as resolved.
Show resolved Hide resolved

var asyncResult = client.BeginUploadFile(memoryStream, remoteFile, ar => asyncResultCallback = ar);
var asyncResult = client.BeginUploadFile(memoryStream, remoteFile, ar =>
{
asyncResultCallback = ar;
callbackCalled.Set();
});

Assert.IsTrue(asyncResult.AsyncWaitHandle.WaitOne(10000));

Expand All @@ -145,6 +150,8 @@ public void Sftp_BeginUploadFile()
Assert.IsFalse(sftpUploadAsyncResult.CompletedSynchronously);
Assert.AreEqual(expectedByteCount, sftpUploadAsyncResult.UploadedBytes);

Assert.IsTrue(callbackCalled.WaitOne(10000));

// check async result callback
var sftpUploadAsyncResultCallback = asyncResultCallback as SftpUploadAsyncResult;
Assert.IsNotNull(sftpUploadAsyncResultCallback);
Expand Down