-
-
Notifications
You must be signed in to change notification settings - Fork 92
Fix Before(Class) and After(Class) hooks running concurrently in different ParallelGroups #3053
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
…ation Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…n parallel groups Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Claude finished @Copilot's task —— View job PR Code ReviewReviewing this pull request that fixes Before(Class) and After(Class) hooks running concurrently in different ParallelGroups. Review Tasks
Code AnalysisHookOrchestrator.cs Changes✅ Positive Aspects:
Test Coverage Analysis✅ Strong Test Implementation:
Performance Analysis✅ Minimal Performance Impact:
Security & Bug Analysis✅ Secure Implementation:
Code Quality Assessment✅ High Quality:
Overall AssessmentStrong implementation that correctly addresses the core issue. The semaphore-based approach is the right solution for preventing race conditions between class-level hooks across parallel groups. Recommendations
Approval Status: ✅ Recommended for merge - This is a solid fix that addresses the reported issue without breaking existing functionality. |
// Check that BeforeClass hooks don't overlap | ||
bool hookOrderCorrect = | ||
(classABeforeEnd < classBBeforeStart) || // A completes before B starts | ||
(classBBeforeEnd < classABeforeStart); // B completes before A starts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be comparing AfterEnd and BeforeStart to meet the comment?
Problem
Before(Class) and After(Class) hooks from different ParallelGroups could execute concurrently, causing resource conflicts and race conditions. This was particularly problematic for database operations where one class's cleanup could interfere with another class's setup:
Previously,
TestClassA.CleanupDatabase()
could run whileTestClassB.SetupDatabase()
was still executing, causing database conflicts.Solution
Added semaphore-based coordination in
HookOrchestrator
to ensure Before(Class) and After(Class) hooks execute sequentially across all ParallelGroups:Implementation Details
SemaphoreSlim(1, 1)
instances to coordinate hook executionExecuteBeforeClassHooksAsync
andExecuteAfterClassHooksAsync
with semaphore acquisitionIDisposable
for automatic semaphore cleanup via existing service disposalImpact
Fixes #3044.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.