Replace blocking Task operations in tests with ManualResetEventSlim#65
Merged
Replace blocking Task operations in tests with ManualResetEventSlim#65
Conversation
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
… - MiniCronTests.EventInvocationOutsideLock.cs Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unit tests for improved reliability
Replace blocking Task operations in tests with ManualResetEventSlim
Jan 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses xUnit1031 warnings about potential deadlocks in test methods by replacing TaskCompletionSource<bool> with ManualResetEventSlim for synchronization primitives used in event handler blocking scenarios.
- Replaces
TaskCompletionSource<bool>withManualResetEventSlimin three test methods - Changes blocking calls from
.Task.GetAwaiter().GetResult()to.Wait() - Updates signaling mechanism from
.SetResult(true)to.Set()
Owner
|
@copilot apply changes based on the comments in this thread |
…niCronTests.EventInvocationOutsideLock.cs Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Contributor
Author
Changes applied. Added |
jeanlrnt
approved these changes
Jan 3, 2026
jeanlrnt
approved these changes
Jan 3, 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.
Fix Tests - Remove Blocking Task Operations ✅
Summary
Successfully fixed 3 xUnit1031 warnings about blocking task operations in test methods by replacing
TaskCompletionSource<bool>withManualResetEventSlimfor proper synchronization, and ensured proper disposal.Changes Made
MiniCronTests.EventInvocationOutsideLock.cs:JobRegistry_JobAdded_InvokedOutsideLock_AllowsConcurrentReads(line 16)JobRegistry_JobRemoved_InvokedOutsideLock_AllowsConcurrentReads(line 64)JobRegistry_JobUpdated_InvokedOutsideLock_AllowsConcurrentReads(line 109)TaskCompletionSource<bool>withManualResetEventSlim(false).Task.GetAwaiter().GetResult()to.Wait().SetResult(true)to.Set()usingstatements for proper disposal ofManualResetEventSliminstancesValidation Results
✅ All 155 tests pass in both Debug and Release configurations
✅ Build succeeds with 0 warnings across all target frameworks (.NET 6, 7, 8, 9, 10)
✅ No code review issues identified
✅ No security vulnerabilities detected by CodeQL
✅ Proper resource disposal with using statements
Technical Details
The tests verify that event handlers run outside the lock to allow concurrent reads.
ManualResetEventSlimimplementsIDisposableand is now properly disposed usingusingstatements, ensuring unmanaged resources are released correctly.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.