Skip to content

Fix flaky test in MainLooperLongTaskStrategyTest#1730

Merged
xgouchet merged 1 commit into
developfrom
xgouchet/flaky/main_looper
Nov 17, 2023
Merged

Fix flaky test in MainLooperLongTaskStrategyTest#1730
xgouchet merged 1 commit into
developfrom
xgouchet/flaky/main_looper

Conversation

@xgouchet

Copy link
Copy Markdown
Contributor

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

codecov-commenter commented Nov 17, 2023

Copy link
Copy Markdown

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
@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