Skip to content

Commit

Permalink
Try to stabilise a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-Hague committed Dec 20, 2023
1 parent 326ce14 commit b20b21b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,11 @@ public void Test_Execute_Command_Asynchronously_With_Callback()
{
callbackCalled = true;
}), null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(100);
}

cmd.EndExecute(asyncResult);

Thread.Sleep(100);

Assert.IsTrue(callbackCalled);

client.Disconnect();
Expand All @@ -318,13 +316,11 @@ public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Threa
{
callbackThreadId = Thread.CurrentThread.ManagedThreadId;
}), null);
while (!asyncResult.IsCompleted)
{
Thread.Sleep(100);
}

cmd.EndExecute(asyncResult);

Thread.Sleep(100);

Assert.AreNotEqual(currentThreadId, callbackThreadId);

client.Disconnect();
Expand Down
7 changes: 1 addition & 6 deletions test/Renci.SshNet.IntegrationTests/SftpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6230,19 +6230,14 @@ public void Sftp_SetLastWriteTimeUtc()
client.Connect();

using var fileStream = new MemoryStream(Encoding.UTF8.GetBytes(testContent));
var currentTime = DateTime.UtcNow;

client.UploadFile(fileStream, testFilePath);
try
{
var time = client.GetLastWriteTimeUtc(testFilePath);

DateTimeAssert.AreEqual(currentTime.TruncateToWholeSeconds(), time);

var newTime = new DateTime(1986, 03, 15, 01, 02, 03, 123, DateTimeKind.Utc);

client.SetLastWriteTimeUtc(testFilePath, newTime);
time = client.GetLastWriteTimeUtc(testFilePath);
var time = client.GetLastWriteTimeUtc(testFilePath);

DateTimeAssert.AreEqual(newTime.TruncateToWholeSeconds(), time);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ private void Arrange()
private void Act()
{
_channel?.Dispose();

Thread.Sleep(200);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public void ForwardedPortShouldAcceptNewConnections()
new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress,
originatorPort))));

Thread.Sleep(200);

_sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once);
channelMock.Verify(p => p.Bind(It.Is<IPEndPoint>(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once);
channelMock.Verify(p => p.Dispose(), Times.Once);
Expand Down
6 changes: 6 additions & 0 deletions test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void IsConnectedShouldReturnTrue()
[TestMethod]
public void SendMessageShouldSendPacketToServer()
{
Thread.Sleep(100);

ServerBytesReceivedRegister.Clear();

Session.SendMessage(_ignoreMessage);
Expand Down Expand Up @@ -123,6 +125,8 @@ public void ISession_MessageListenerCompletedShouldNotBeSignaled()
[TestMethod]
public void ISession_SendMessageShouldSendPacketToServer()
{
Thread.Sleep(100);

var session = (ISession) Session;
ServerBytesReceivedRegister.Clear();

Expand All @@ -137,6 +141,8 @@ public void ISession_SendMessageShouldSendPacketToServer()
[TestMethod]
public void ISession_TrySendMessageShouldSendPacketToServerAndReturnTrue()
{
Thread.Sleep(100);

var session = (ISession) Session;
ServerBytesReceivedRegister.Clear();

Expand Down

0 comments on commit b20b21b

Please sign in to comment.