-
-
Notifications
You must be signed in to change notification settings - Fork 111
fix: make thread assertion tests deterministic #4570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replace Thread.Sleep() with ManualResetEventSlim synchronization to ensure threads stay alive until assertions complete. This fixes flaky test failures where ThreadStateException was thrown because the thread completed before IsThreadPoolThread could be accessed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes flaky thread assertion tests by replacing timing-based synchronization (Thread.Sleep) with deterministic event-based synchronization (ManualResetEventSlim). Critical IssuesNone found ✅ The changes correctly address the race condition that was causing ThreadStateException: Thread is dead; state cannot be accessed. The new pattern ensures:
SuggestionsNone - the implementation is clean and follows proper synchronization patterns. Verdict✅ APPROVE - No critical issues The PR fixes a legitimate test flakiness issue with proper synchronization primitives. The duplicate import removal is a nice cleanup bonus. |
Summary
Test_Thread_IsNotThreadPoolThread_NewThreadtest that was failing withThreadStateException: Thread is dead; state cannot be accessedThread.Sleep()withManualResetEventSlimsynchronization inTest_Thread_IsAlive_NewThread,Test_Thread_IsBackground_Started, andTest_Thread_IsNotThreadPoolThread_NewThreadusing TUnit.Assertions.Extensions;importTest plan
🤖 Generated with Claude Code