Skip to content

Commit

Permalink
fix flaky SFTP file time tests (#1414)
Browse files Browse the repository at this point in the history
* fix flaky SFTP file time tests

These asserts currently assume that DateTime.Now and the
creation timestamp on the server happen within the same second.

Note that I didn't change the asserts below where an explicit
timestamp is set. From my understanding, these should not be affected.

example: https://ci.appveyor.com/project/drieseng/ssh-net/builds/49850731/job/u6lk0cyipbxkp4jd

* remove asserts
  • Loading branch information
mus65 authored Jun 4, 2024
1 parent fdbc4d3 commit dda27a3
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions test/Renci.SshNet.IntegrationTests/SftpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6142,20 +6142,15 @@ public void Sftp_SetLastAccessTime()
client.Connect();

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

client.UploadFile(fileStream, testFilePath);

try
{
var time = client.GetLastAccessTime(testFilePath);

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

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

client.SetLastAccessTime(testFilePath, newTime);
time = client.GetLastAccessTime(testFilePath);
var time = client.GetLastAccessTime(testFilePath);

DateTimeAssert.AreEqual(newTime.TruncateToWholeSeconds(), time);
}
Expand All @@ -6175,19 +6170,14 @@ public void Sftp_SetLastAccessTimeUtc()
client.Connect();

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

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

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

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

client.SetLastAccessTimeUtc(testFilePath, newTime);
time = client.GetLastAccessTimeUtc(testFilePath);
var time = client.GetLastAccessTimeUtc(testFilePath);

DateTimeAssert.AreEqual(newTime.TruncateToWholeSeconds(), time);
}
Expand All @@ -6206,19 +6196,14 @@ public void Sftp_SetLastWriteTime()
client.Connect();

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

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

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

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

client.SetLastWriteTime(testFilePath, newTime);
time = client.GetLastWriteTime(testFilePath);
var time = client.GetLastWriteTime(testFilePath);

DateTimeAssert.AreEqual(newTime.TruncateToWholeSeconds(), time);
}
Expand Down

0 comments on commit dda27a3

Please sign in to comment.