Fix ProcessThreadTests.TestStartTimeProperty flakiness due to /proc visibility race#125811
Open
Fix ProcessThreadTests.TestStartTimeProperty flakiness due to /proc visibility race#125811
Conversation
…y loop Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ProcessThreadTests.TestStartTimeProperty failure in CI
Fix ProcessThreadTests.TestStartTimeProperty flakiness due to /proc visibility race
Mar 20, 2026
Contributor
There was a problem hiding this comment.
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.
src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs
Outdated
Show resolved
Hide resolved
- 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>
danmoseley
approved these changes
Mar 20, 2026
This was referenced Mar 20, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.