Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,19 @@ public async Task TestStartTimeProperty()
// that there's at least one thread greater than the current time we previously grabbed.
await Task.Factory.StartNew(() =>
{
p.Refresh();

int newThreadId = GetCurrentThreadId();

ProcessThread[] processThreads = p.Threads.Cast<ProcessThread>().ToArray();
ProcessThread newThread = Assert.Single(processThreads, thread => thread.Id == newThreadId);
// Retry to handle the race where the newly started thread is not yet visible via Process.Threads.
ProcessThread newThread = null;
for (int i = 0; i < 10 && newThread is null; i++)
{
if (i > 0) Thread.Sleep(100);
p.Refresh();
newThread = p.Threads.Cast<ProcessThread>().FirstOrDefault(t => t.Id == newThreadId);
}

Assert.InRange(newThread.StartTime.ToUniversalTime(), curTime - allowedWindow, DateTime.Now.ToUniversalTime() + allowedWindow);
Assert.True(newThread is not null, $"Thread with id {newThreadId} was not found after retrying.");
Assert.InRange(newThread.StartTime.ToUniversalTime(), curTime - allowedWindow, DateTime.UtcNow + allowedWindow);
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
}
Expand Down
Loading