Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martincostello
Copy link
Member

@martincostello martincostello commented Jun 11, 2025

Changes

  • Avoid InvalidOperationException by copying collection before passing to Any().
  • Refactor 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

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Avoid `InvalidOperationException` by copying collection before passing to `Any()`.
- Refactor `while` loop to improve readability.
@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 09:16
@martincostello martincostello requested a review from a team as a code owner June 11, 2025 09:16
Copy link

@Copilot 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 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);

@github-actions github-actions bot added the comp:instrumentation.hangfire Things related to OpenTelemetry.Instrumentation.Hangfire label Jun 11, 2025
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.58%. Comparing base (71655ce) to head (801077e).
Report is 875 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
unittests-Instrumentation.Hangfire 93.58% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 261 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@TimothyMothra TimothyMothra left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.hangfire Things related to OpenTelemetry.Instrumentation.Hangfire
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants