-
Notifications
You must be signed in to change notification settings - Fork 332
[Hangfire] Fix flaky test #2835
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
base: main
Are you sure you want to change the base?
[Hangfire] Fix flaky test #2835
Conversation
- Avoid `InvalidOperationException` by copying collection before passing to `Any()`. - Refactor `while` loop to improve readability.
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.
Pull Request Overview
This PR fixes a flaky test by avoiding an InvalidOperationException through copying the job history collection, and refactors the wait loop for better readability.
- Replace DateTime timeout check with a CancellationTokenSource based on a TimeSpan
- Extract a local Completed() function that copies the job history to avoid modification exceptions
Comments suppressed due to low confidence (2)
test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs:185
- [nitpick] Consider renaming the local function 'Completed' to 'IsJobCompleted' to more clearly indicate that it returns a boolean value assessing job completion.
bool Completed()
test/OpenTelemetry.Instrumentation.Hangfire.Tests/HangfireInstrumentationJobFilterAttributeTests.cs:182
- Consider passing the cancellation token to Task.Delay (e.g., Task.Delay(500, cts.Token)) to allow the loop to exit promptly when the token is cancelled.
await Task.Delay(500);
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #2835 +/- ##
===========================================
+ Coverage 73.91% 93.58% +19.67%
===========================================
Files 267 4 -263
Lines 9615 78 -9537
===========================================
- Hits 7107 73 -7034
+ Misses 2508 5 -2503
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
LGTM
Changes
InvalidOperationException
by copying collection before passing toAny()
.while
loop to improve readability.Have also created this PR to avoid the problem in the library the tests use: perrich/Hangfire.MemoryStorage#47
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes