Skip to content

test: fix flaky ObjectInitializer continuation-thread test - #6932

Merged
thomhurst merged 1 commit into
mainfrom
fix/flaky-object-initializer-thread-id
Sep 29, 2026
Merged

thomhurst merged 1 commit into
mainfrom
fix/flaky-object-initializer-thread-id

Conversation

@thomhurst

@thomhurst thomhurst commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

ObjectInitializerTests.Waiting_Continuations_Do_Not_Run_On_The_Initializing_Thread failed on macOS CI (run 36556399225) with Expected to not be equal to 17.

Cause: the test runs initialization on a TaskCreationOptions.LongRunning dedicated thread, which exits as soon as initialization finishes. It then compared Environment.CurrentManagedThreadId values. 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.CurrentThread and assert IsNotSameReferenceAs. A new thread-pool thread is always a different Thread object, even when it gets the same ID. The assertion still checks the same behaviour.

Test plan

  • Ran the test (both arguments) 25 times in a row on net10.0 Release: 25/25 passed.
  • The whole ObjectInitializerTests class passes: 11/11.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved validation that waiter continuations run on a different thread from the one performing initialization.

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>
@thomhurst
thomhurst deployed to Pull Requests September 29, 2026 14:21 — with GitHub Actions Active
@thomhurst
thomhurst deployed to Pull Requests September 29, 2026 14:21 — with GitHub Actions Active
@thomhurst
thomhurst deployed to Pull Requests September 29, 2026 14:21 — with GitHub Actions Active
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T14:23:23.980127Z 86a7b33 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2c6e858c-d25c-4150-85d2-a341e65a501a

📥 Commits

Reviewing files that changed from the base of the PR and between c496882 and 86a7b33.

📒 Files selected for processing (1)
  • tests/TUnit.UnitTests/ObjectInitializerTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The object initializer test now tracks the initializing thread and waiter continuation threads as Thread objects. It asserts that the initializing thread is non-null and that each waiter continuation runs on a different thread object.

Changes

Object initializer thread test

Layer / File(s) Summary
Thread identity assertions
tests/TUnit.UnitTests/ObjectInitializerTests.cs
The test records the initializing thread and waiter continuation threads as Thread objects. It checks that the initializing thread is non-null and compares thread references.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~7 minutes

Change: Other

Suggested reviewers: sing303

Merge Risk: ⚪ Minimal · up to 86a7b

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the flaky ObjectInitializer continuation-thread test and the corrective change. It is concise and directly related to the main purpose of the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

A rabbit checks each thread with care,
The initializing thread is there.
Waiters take a different track,
No managed IDs to compare back.
The test now watches objects hop,
Then marks its tidy check complete.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Review: LGTM.

The diagnosis is sound. ManagedThreadId can be recycled after the LongRunning thread exits, so comparing Thread references is the right fix. It keeps the same intent, because a distinct live or dead Thread object is never the same reference. The added IsNotNull guard on initializingThread is a good touch: without it, a null would make IsNotSameReferenceAs pass vacuously against a never-assigned value.

Minor, non-blocking: holding the Thread reference keeps the exited thread object alive until the test ends. That is harmless here.

No issues found.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low risk]

The PR appears safe to merge.

Summary

The PR changes a test to compare Thread objects rather than managed thread IDs, avoiding a false failure when a dedicated thread’s ID is reused.

  • The assertion API and initializer lifecycle support the revised check.

Reviews (1) · Last reviewed commit: "test: compare Thread identity in ObjectI..."

@thomhurst
thomhurst enabled auto-merge (squash) September 29, 2026 14:24
@thomhurst
thomhurst disabled auto-merge September 29, 2026 14:32
@thomhurst
thomhurst enabled auto-merge (squash) September 29, 2026 14:32
@thomhurst
thomhurst disabled auto-merge September 29, 2026 14:40
@thomhurst
thomhurst enabled auto-merge (squash) September 29, 2026 14:40
@thomhurst
thomhurst merged commit a703e6f into main Sep 29, 2026
21 checks passed
@thomhurst
thomhurst deleted the fix/flaky-object-initializer-thread-id branch September 29, 2026 15:04
This was referenced Sep 30, 2026

This branch was successfully deployed

1 active deployment
Pull Requests — 86a7b335 Deployed Sep 29, 2026 by thomhurst via modularpipeline (ubuntu-latest) #19616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant