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.
This commit is contained in:
Cédric Luthi 2021-08-20 14:42:03 +02:00 committed by Patrik Svensson
parent e081593012
commit ffd24ec451

View File

@ -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);
});