Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

Fix Tests - Remove Blocking Task Operations ✅

Summary

Successfully fixed 3 xUnit1031 warnings about blocking task operations in test methods by replacing TaskCompletionSource<bool> with ManualResetEventSlim for proper synchronization, and ensured proper disposal.

Changes Made

  • Fixed 3 tests in MiniCronTests.EventInvocationOutsideLock.cs:
    • JobRegistry_JobAdded_InvokedOutsideLock_AllowsConcurrentReads (line 16)
    • JobRegistry_JobRemoved_InvokedOutsideLock_AllowsConcurrentReads (line 64)
    • JobRegistry_JobUpdated_InvokedOutsideLock_AllowsConcurrentReads (line 109)
  • Replaced TaskCompletionSource<bool> with ManualResetEventSlim(false)
  • Changed .Task.GetAwaiter().GetResult() to .Wait()
  • Changed .SetResult(true) to .Set()
  • Added using statements for proper disposal of ManualResetEventSlim instances

Validation 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. ManualResetEventSlim implements IDisposable and is now properly disposed using using statements, ensuring unmanaged resources are released correctly.

Original prompt

Fix tests


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix unit tests for improved reliability Replace blocking Task operations in tests with ManualResetEventSlim Jan 2, 2026
Copilot AI requested a review from jeanlrnt January 2, 2026 14:37
@jeanlrnt jeanlrnt marked this pull request as ready for review January 2, 2026 19:35
Copilot AI review requested due to automatic review settings January 2, 2026 19:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> with ManualResetEventSlim in three test methods
  • Changes blocking calls from .Task.GetAwaiter().GetResult() to .Wait()
  • Updates signaling mechanism from .SetResult(true) to .Set()

@jeanlrnt
Copy link
Owner

jeanlrnt commented Jan 3, 2026

@copilot apply changes based on the comments in this thread

…niCronTests.EventInvocationOutsideLock.cs

Co-authored-by: jeanlrnt <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 3, 2026

@copilot apply changes based on the comments in this thread

Changes applied. Added using statements for all three ManualResetEventSlim instances to ensure proper disposal of unmanaged resources in commit 83d3fb4.

Copilot AI requested a review from jeanlrnt January 3, 2026 13:32
@jeanlrnt jeanlrnt merged commit cd0b814 into main Jan 3, 2026
4 checks passed
@jeanlrnt jeanlrnt deleted the copilot/fix-tests branch January 3, 2026 13:33
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.

2 participants