Skip to content

Commit

Permalink
Relax unit test file time checking on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuckow committed Jan 4, 2021
1 parent d4e6139 commit 4cdeaa9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Duplicati/UnitTest/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common.IO;
using NUnit.Framework;
using System.Runtime.InteropServices;

namespace Duplicati.UnitTest
{
Expand Down Expand Up @@ -243,13 +244,17 @@ public static void AssertFilesAreEqual(string expectedFile, string actualFile, b
// Compare file metadata
if (verifymetadata)
{
//OSX seem to like to actually set the time to some value earlier than what you set by tens of milliseconds.
//Reading the time right after it is set gives the expected value but when read later it is slightly different.
//Maybe a bug in .net?
var granularity = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 100 : 1;
Assert.That(
SystemIO.IO_OS.GetLastWriteTimeUtc(actualFile),
Is.EqualTo(SystemIO.IO_OS.GetLastWriteTimeUtc(expectedFile)).Within(1).Milliseconds,
Is.EqualTo(SystemIO.IO_OS.GetLastWriteTimeUtc(expectedFile)).Within(granularity).Milliseconds,
$"{contextMessage}, last write time mismatch for {expectedFile} and {actualFile}");
Assert.That(
SystemIO.IO_OS.GetCreationTimeUtc(actualFile),
Is.EqualTo(SystemIO.IO_OS.GetCreationTimeUtc(expectedFile)).Within(1).Milliseconds,
Is.EqualTo(SystemIO.IO_OS.GetCreationTimeUtc(expectedFile)).Within(granularity).Milliseconds,
$"{contextMessage}, creation time mismatch for {expectedFile} and {actualFile}");
}
}
Expand Down

0 comments on commit 4cdeaa9

Please sign in to comment.