From 1143ad3d2404500b975cfc1e67a77ea774f96cf2 Mon Sep 17 00:00:00 2001 From: mus65 Date: Sat, 18 May 2024 21:25:03 +0200 Subject: [PATCH] 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 --- test/Renci.SshNet.IntegrationTests/SftpTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/Renci.SshNet.IntegrationTests/SftpTests.cs b/test/Renci.SshNet.IntegrationTests/SftpTests.cs index 689a2c3b..5b8373f6 100644 --- a/test/Renci.SshNet.IntegrationTests/SftpTests.cs +++ b/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);