You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TestStartTimeProperty was flaky (especially on Mono/Linux) because after a new LongRunning thread starts, its /proc/self/task/ entry may not be visible immediately. The previous code called p.Refresh() once then used Assert.Single, failing hard if the entry wasn't ready yet.
Description
Replace the single-shot refresh + Assert.Single with a bounded retry loop that re-calls p.Refresh() until the thread appears (up to 10 attempts, 100ms apart):
intnewThreadId=GetCurrentThreadId();ProcessThreadnewThread=null;for(inti=0;i<10&&newThreadisnull;i++){if(i>0)Thread.Sleep(100);p.Refresh();newThread=p.Threads.Cast<ProcessThread>().FirstOrDefault(t =>t.Id==newThreadId);}Assert.True(newThreadis not null,$"Thread with id {newThreadId} was not found after retrying.");Assert.InRange(newThread.StartTime.ToUniversalTime(),curTime-allowedWindow,DateTime.Now.ToUniversalTime()+allowedWindow);
Gets the thread ID before any refresh attempt
Uses FirstOrDefault (not Assert.Single) during the search phase to avoid spurious failures
Fails with a descriptive message if the thread still isn't visible after ~900ms of retries
This section details on the original issue you should resolve
<issue_title>ProcessThreadTests.TestStartTimeProperty failure in CI</issue_title>
<issue_description>```
System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty [FAIL]
Assert.Single() Failure: The collection did not contain any matching items
Expected: (predicate expression)
Collection: [System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, ···]
Stack Trace:
//src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs(156,0): at System.Diagnostics.Tests.ProcessThreadTests.<>c__DisplayClass4_2.b__0()
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2396,0): at System.Threading.Tasks.Task.InnerInvoke()
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2384,0): at System.Threading.Tasks.Task.<>c.<.cctor>b__292_0(Object obj)
//src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(179,0): at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
//src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(203,0): at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2342,0): at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
/_/src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs(149,0): at System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty()
--- End of stack trace from previous location ---
## Build Information
Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=755830
Build error leg or test failing: System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty
Pull request: https://github.com/dotnet/runtime/pull/105519
<!-- Error message template -->
## Error Message
Fill the error message using [step by step known issues guidance](https://github.com/dotnet/arcade/blob/main/Documentation/Projects/Build%20Analysis/KnownIssueJsonStepByStep.md).
<!-- Use ErrorMessage for String.Contains matches. Use ErrorPattern for regex matches (single line/no backtracking). Set BuildRetry to `true` to retry builds with this error. Set ExcludeConsoleLog to `true` to skip helix logs analysis. -->
```json
{
"ErrorMessage": ["System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty [FAIL]","The collection did not contain any matching items"],
"ErrorPattern": "",
"BuildRetry": false,
"ExcludeConsoleLog": false
}
Known issue validation
Build: 🔎https://dev.azure.com/dnceng-public/public/_build/results?buildId=755830 Error message validated:[System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty [FAIL] The collection did not contain any matching items] Result validation: ✅ Known issue matched with the provided build. Validation performed at: 7/26/2024 12:06:54 AM UTC
CopilotAI
changed the title
[WIP] Fix ProcessThreadTests.TestStartTimeProperty failure in CIFix ProcessThreadTests.TestStartTimeProperty flakiness due to /proc visibility raceMar 20, 2026
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR reduces flakiness in ProcessThreadTests.TestStartTimeProperty by handling a race where a newly started thread may not immediately appear in Process.Threads (notably on Linux/Mono), replacing a single-shot refresh + Assert.Single with a bounded retry loop.
Changes:
Remove the single p.Refresh() + Assert.Single(...) lookup for the spawned thread.
Add a bounded retry loop that refreshes and searches for the thread by ID before asserting.
Improve failure behavior by emitting a clearer assertion message when the thread never becomes visible.
- Reword /proc-specific comment to be platform-agnostic
- Use DateTime.UtcNow instead of DateTime.Now.ToUniversalTime()
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TestStartTimePropertywas flaky (especially on Mono/Linux) because after a newLongRunningthread starts, its/proc/self/task/entry may not be visible immediately. The previous code calledp.Refresh()once then usedAssert.Single, failing hard if the entry wasn't ready yet.Description
Replace the single-shot refresh +
Assert.Singlewith a bounded retry loop that re-callsp.Refresh()until the thread appears (up to 10 attempts, 100ms apart):FirstOrDefault(notAssert.Single) during the search phase to avoid spurious failuresOriginal prompt
This section details on the original issue you should resolve
<issue_title>ProcessThreadTests.TestStartTimeProperty failure in CI</issue_title>
<issue_description>```
System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty [FAIL]
Assert.Single() Failure: The collection did not contain any matching items
Expected: (predicate expression)
Collection: [System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, System.Diagnostics.ProcessThread, ···]
Stack Trace:
//src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs(156,0): at System.Diagnostics.Tests.ProcessThreadTests.<>c__DisplayClass4_2.b__0()
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2396,0): at System.Threading.Tasks.Task.InnerInvoke()
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2384,0): at System.Threading.Tasks.Task.<>c.<.cctor>b__292_0(Object obj)
//src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(179,0): at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
//src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs(203,0): at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
//src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs(2342,0): at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
/_/src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs(149,0): at System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty()
--- End of stack trace from previous location ---
Known issue validation
Build: 🔎https://dev.azure.com/dnceng-public/public/_build/results?buildId=755830
Error message validated:
[System.Diagnostics.Tests.ProcessThreadTests.TestStartTimeProperty [FAIL] The collection did not contain any matching items]Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 7/26/2024 12:06:54 AM UTC
Report
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.