Skip to content
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

Fix flaky test in MainLooperLongTaskStrategyTest #1730

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

xgouchet
Copy link
Member

What does this PR do?

Fix a flaky test in MainLooperLongTaskStrategyTest.

Flakiness arise from the way multithreading can introduce some delays, and some suboptimal assertions:

  • Probably a long task would be detected, we used Thread.sleep(duration + 1), which is a bit weird.
    • we adjusted the random duration to always be 1 more than the threshold.
  • The assertion used .isCloseTo(duration, offset), which would be the same as .isBetween(duration - offset, duration + offset). This assertion is not perfect as a detected value less than duration is impossible, and wrong.
    • We adjusted it to be .isBetween(duration, duration + 16L)
  • The offset itself was set to 10 millisecond, which would prove sometimes to small locally (5% of occurences)
    • We increased it to 16 ms

Note

Although this reduces drastically the flakiness of this test, it can sometimes happen (once every 1000 run or so) that a GC or other stuff will delay the test run, and result in a failing test.

@xgouchet xgouchet requested review from a team as code owners November 17, 2023 08:39
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2023

Codecov Report

Merging #1730 (7e1035c) into develop (9457e96) will decrease coverage by 0.04%.
Report is 6 commits behind head on develop.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1730      +/-   ##
===========================================
- Coverage    83.41%   83.37%   -0.04%     
===========================================
  Files          465      465              
  Lines        16173    16170       -3     
  Branches      2407     2406       -1     
===========================================
- Hits         13490    13481       -9     
- Misses        2027     2028       +1     
- Partials       656      661       +5     

see 17 files with indirect coverage changes

@xgouchet xgouchet merged commit 8e099c0 into develop Nov 17, 2023
5 checks passed
@xgouchet xgouchet deleted the xgouchet/flaky/main_looper branch November 17, 2023 13:16
@xgouchet xgouchet added this to the 2.3.0 milestone Dec 13, 2023
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.

4 participants