mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
fix flaky Sftp_BeginUploadFile test (#1402)
* fix flaky Sftp_BeginUploadFile test this test can randomly fail because it assumes that the callback has been called when the AsyncWaitHandle was set. But this is not necessarily the case because AsyncResult.SetAsCompleted does it the other way around. example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49831002/job/1237d4lg46j22pf0 * use ManualResetEventSlim --------- Co-authored-by: Rob Hague <rob.hague00@gmail.com>
This commit is contained in:
@@ -132,8 +132,13 @@ namespace Renci.SshNet.IntegrationTests
|
||||
using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(content)))
|
||||
{
|
||||
IAsyncResult asyncResultCallback = null;
|
||||
using var callbackCalled = new ManualResetEventSlim(false);
|
||||
|
||||
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));
|
||||
|
||||
@@ -145,6 +150,8 @@ namespace Renci.SshNet.IntegrationTests
|
||||
Assert.IsFalse(sftpUploadAsyncResult.CompletedSynchronously);
|
||||
Assert.AreEqual(expectedByteCount, sftpUploadAsyncResult.UploadedBytes);
|
||||
|
||||
Assert.IsTrue(callbackCalled.Wait(10000));
|
||||
|
||||
// check async result callback
|
||||
var sftpUploadAsyncResultCallback = asyncResultCallback as SftpUploadAsyncResult;
|
||||
Assert.IsNotNull(sftpUploadAsyncResultCallback);
|
||||
|
||||
Reference in New Issue
Block a user