Skip to content

Commit

Permalink
Try to stabilise a few tests (#1278)
Browse files Browse the repository at this point in the history
* Try to stabilise a few tests

* Fix random 0 buffer sizes

---------

Co-authored-by: Wojciech Nagórski <[email protected]>
  • Loading branch information
Rob-Hague and WojciechNagorski authored Dec 22, 2023
1 parent 24838e6 commit b0d01df
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 77 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(3, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(3, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(3, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected override void SetupData()
var random = new Random();
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(2, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(2, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(2, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(random.Next(1, 5), random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(2, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected override void SetupData()
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_handle = GenerateRandom(2, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ protected override void SetupData()
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_handle = GenerateRandom(7, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(1, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
}

protected override void SetupMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected void Arrange()
_path = random.Next().ToString();
_handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)};
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);

_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(4, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected override void SetupData()
_path = random.Next().ToString();
_handle = GenerateRandom(5, random);
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected void Arrange()
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)};
_bufferSize = (uint) random.Next(1, 1000);
_readBufferSize = (uint) random.Next(0, 1000);
_writeBufferSize = (uint) random.Next(0, 1000);
_readBufferSize = (uint) random.Next(1, 1000);
_writeBufferSize = (uint) random.Next(1, 1000);
_length = random.Next();

_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
Expand Down
Loading

0 comments on commit b0d01df

Please sign in to comment.