Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 303c14d

Browse files
author
Lakshmi Priya Sekar
committed
BugFix: Fix flaky Process.StartTime test on Linux.
1 parent 7859c07 commit 303c14d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/System.Diagnostics.Process/tests/ProcessTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void TestProcessorTime()
364364
Assert.InRange(processorTimeAtHalfSpin, processorTimeBeforeSpin, Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds);
365365
}
366366

367-
[Fact, ActiveIssue("https://github.com/dotnet/corefx/issues/2613", PlatformID.Linux)]
367+
[Fact]
368368
public void TestProcessStartTime()
369369
{
370370
DateTime timeBeforeCreatingProcess = DateTime.UtcNow;
@@ -378,18 +378,19 @@ public void TestProcessStartTime()
378378
// Time in unix, is measured in jiffies, which is incremented by one for every timer interrupt since the boot time.
379379
// Thus, because there are HZ timer interrupts in a second, there are HZ jiffies in a second. Hence 1\HZ, will
380380
// be the resolution of system timer. The lowest value of HZ on unix is 100, hence the timer resolution is 10 ms.
381-
// Allowing for error in 10 ms.
382-
long tenMSTicks = new TimeSpan(0, 0, 0, 0, 10).Ticks;
383-
long beforeTicks = timeBeforeCreatingProcess.Ticks - tenMSTicks;
381+
// On Windows, timer resolution is 15 ms from MSDN DateTime.Now. Hence, allowing error in 15ms [max(10,15)].
382+
383+
long intervalTicks = new TimeSpan(0, 0, 0, 0, 15).Ticks;
384+
long beforeTicks = timeBeforeCreatingProcess.Ticks - intervalTicks;
384385

385386
try
386387
{
387388
// Ensure the process has started, p.id throws InvalidOperationException, if the process has not yet started.
388389
Assert.Equal(p.Id, Process.GetProcessById(p.Id).Id);
389-
390-
long afterTicks = DateTime.UtcNow.Ticks + tenMSTicks;
391-
Assert.InRange(p.StartTime.ToUniversalTime().Ticks, beforeTicks, afterTicks);
392-
}
390+
long startTicks = p.StartTime.ToUniversalTime().Ticks;
391+
long afterTicks = DateTime.UtcNow.Ticks + intervalTicks;
392+
Assert.InRange(startTicks, beforeTicks, afterTicks);
393+
}
393394
catch (InvalidOperationException)
394395
{
395396
Assert.True(p.StartTime.ToUniversalTime().Ticks > beforeTicks);

0 commit comments

Comments
 (0)