Skip to content

Commit 1143ad3

Browse files
mus65Rob-Hague
andauthored
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 <[email protected]>
1 parent fcb4ea2 commit 1143ad3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/Renci.SshNet.IntegrationTests/SftpTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ public void Sftp_BeginUploadFile()
132132
using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(content)))
133133
{
134134
IAsyncResult asyncResultCallback = null;
135+
using var callbackCalled = new ManualResetEventSlim(false);
135136

136-
var asyncResult = client.BeginUploadFile(memoryStream, remoteFile, ar => asyncResultCallback = ar);
137+
var asyncResult = client.BeginUploadFile(memoryStream, remoteFile, ar =>
138+
{
139+
asyncResultCallback = ar;
140+
callbackCalled.Set();
141+
});
137142

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

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

153+
Assert.IsTrue(callbackCalled.Wait(10000));
154+
148155
// check async result callback
149156
var sftpUploadAsyncResultCallback = asyncResultCallback as SftpUploadAsyncResult;
150157
Assert.IsNotNull(sftpUploadAsyncResultCallback);

0 commit comments

Comments
 (0)