-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
refactor: CardBrowserTest + fix flaky tests #12263
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
david-allison
added
Review High Priority
Request for high priority review
Needs Review
labels
Aug 31, 2022
This comment was marked as resolved.
This comment was marked as resolved.
david-allison
added
Needs Author Reply
Waiting for a reply from the original author
and removed
Review High Priority
Request for high priority review
Needs Review
labels
Aug 31, 2022
Before the introduction of `SingleTaskManager`, all `CollectionTask`s required `advanceRobolectricLooper()`` After `SingleTaskManager`, CollectionTask no longer required `advanceRobolectricLooper()` to execute. Sometimes `advanceRobolectricLooper` was required for non CollectionTask-based calls (for example: calling `onCreateOptionsMenu` at the correct time) We currently use `@RunInBackground` to use the old behaviour. This is not ideal as `advanceRobolectricLooperWithSleep` adds 500ms per call to the unit tests `advanceRobolectricUiLooper` method exists for the migration away from @RunInBackground, where calls are known to be necessary The overall aim is: * Remove `@RunInBackground` and replace with `advanceRobolectricUiLooper` calls when necessary * Remove ALL legacy calls to `advanceRobolectricLooperWithSleep` * Lots of these exist as a partial migration from `@RunInBackground` * Remove ALL legacy calls to `advanceRobolectricLooper`
introduce: `advanceRobolectricUiLooper` on - `selectMenuItem` - `selectOneOfManyCards` Remove all unnecessary calls to: - `advanceRobolectricLooperWithSleep`
- grantWritePermissions - revokeWritePermissions
Introduce `withNoWritePermission` so this error is no longer possible We have flaky tests on this class, and it likely is not an issue but it seems wrong, and the fix is trivial
david-allison
force-pushed
the
fix-CardBrowserTest
branch
from
August 31, 2022 23:12
b95456c
to
8838b3d
Compare
I'm going to run the Windows CI a few times to see if this is fixed by 8f0c0e2
|
``` CardBrowserTest > browserIsInMultiSelectModeWhenSelectingAll FAILED java.lang.AssertionError: Expected: <true> but: was <false> at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20) at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6) at com.ichi2.anki.CardBrowserTest.browserIsInMultiSelectModeWhenSelectingAll(CardBrowserTest.kt:116) CardBrowserTest > moveToNonDynamicDeckWorks FAILED java.lang.IllegalStateException: Attempted to check card at index 0. 0 cards available at com.ichi2.anki.CardBrowser.checkCardsAtPositions(CardBrowser.kt:2533) at com.ichi2.anki.CardBrowserTest.moveToNonDynamicDeckWorks(CardBrowserTest.kt:207) ```
david-allison
added
Review High Priority
Request for high priority review
Needs Review
and removed
Needs Author Reply
Waiting for a reply from the original author
labels
Sep 1, 2022
david-allison
changed the title
refactor: CardBrowserTest + maybe fix flaky tests
refactor: CardBrowserTest + fix flaky tests
Sep 1, 2022
mikehardy
approved these changes
Sep 1, 2022
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.
All seem sensible - thanks for brooming there and sweeping up
github-actions
bot
removed
Needs Review
Review High Priority
Request for high priority review
labels
Sep 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose / Description
I was investigating the flaky unit tests, and wanted to see what was going on
I could not reproduce the test failure, but a few frustrations occurred:
Robolectric.startActivity
was introduced@KotlinCleanup
s@RunInBackground
was used, which is pending for removalrevokeWritePermissions
not being reset, which may have caused test failuresI fixed all of these, and introduced
advanceRobolectricUiLooper
to allow for further migration away from@RunInBackground
I then added another
advanceRobolectricUiLooper
after creating theActivity
, and the problems went away#11091
How Has This Been Tested?
Test only - tests run about 2 seconds faster expected - we shave 4*500ms off tests
Learning
advanceRobolectricUiLooper
is still required -onCreateOptionsMenu
was not called otherwise due to an updateChecklist