From ffd24ec451315d6cdcda7a610caf30dc388e295e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Fri, 20 Aug 2021 14:42:03 +0200 Subject: [PATCH] Fix intermittent test failure When running on .NET Framework, the `Should_Report_Max_Remaining_Time_For_Extremely_Small_Progress` would intermittently fail with the following error: ``` task.RemainingTime should be 10675199.02:48:05.4775807 but was null ``` This is because it's possible that the two increment share the same timestamp thus making the `RemainingTime` null. To ensure the two increments don't share the same timestamp, we sleep for one millisecond. Although I have only observed this issue on .NET Framework it would be possible that it occasionally also occur on .NET Core. --- .../Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs index 9f93d67..c775a9c 100644 --- a/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs +++ b/test/Spectre.Console.Tests/Unit/Live/Progress/ProgressTests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Shouldly; using Spectre.Console.Testing; @@ -261,6 +262,9 @@ namespace Spectre.Console.Tests.Unit { task = ctx.AddTask("foo"); task.Increment(double.Epsilon); + // Make sure that at least one millisecond has elapsed between the increments else the RemainingTime is null + // when the last timestamp is equal to the first timestamp of the samples. + Thread.Sleep(1); task.Increment(double.Epsilon); });