test: fix flaky ObjectInitializer continuation-thread test - #6932
Conversation
The initializing thread is a LongRunning dedicated thread that exits once initialization finishes. The runtime can then reuse its ManagedThreadId for a thread-pool thread that runs a correctly queued waiter continuation, which made the IsNotEqualTo(threadId) check fail spuriously (seen on macOS CI). Compare Thread object references instead, which stay distinct. Co-Authored-By: Claude <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe object initializer test now tracks the initializing thread and waiter continuation threads as ChangesObject initializer thread test
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~7 minutes Change: Other Suggested reviewers: Merge Risk: ⚪ Minimal · up to This test-only change avoids false failures from reused thread IDs while preserving the regression scenario. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks each thread with care, Comment |
|
Review: LGTM. The diagnosis is sound. Minor, non-blocking: holding the No issues found. |
|
Summary
ObjectInitializerTests.Waiting_Continuations_Do_Not_Run_On_The_Initializing_Threadfailed on macOS CI (run 36556399225) withExpected to not be equal to 17.Cause: the test runs initialization on a
TaskCreationOptions.LongRunningdedicated thread, which exits as soon as initialization finishes. It then comparedEnvironment.CurrentManagedThreadIdvalues. The runtime can give a dead thread's managed ID to a new thread-pool thread, and that thread can run a correctly queued waiter continuation. The IDs then match even though the product code behaved correctly.Fix: capture
Thread.CurrentThreadand assertIsNotSameReferenceAs. A new thread-pool thread is always a differentThreadobject, even when it gets the same ID. The assertion still checks the same behaviour.Test plan
ObjectInitializerTestsclass passes: 11/11.🤖 Generated with Claude Code
Summary by CodeRabbit