ソースを参照

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>
mus65 1 年間 前
コミット
1143ad3d24
1 ファイル変更8 行追加1 行削除
  1. 8 1
      test/Renci.SshNet.IntegrationTests/SftpTests.cs

+ 8 - 1
test/Renci.SshNet.IntegrationTests/SftpTests.cs

@@ -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);