Conversation
This commit fixes the flaky-tests issue faced in the dual boot environment of Windows 11 and Ubuntu Linux caused due to TimeZone conditions and race conditions in ReviewerTest.kt and AlarmManagerServiceTest.kt
| @Before | ||
| override fun setUp() { | ||
| super.setUp() | ||
| TimeZone.setDefault(TimeZone.getTimeZone("UTC")) |
There was a problem hiding this comment.
Won't this fail at the same time in UTC?
| assertDoesNotThrow { | ||
| ChangeManager.notifySubscribers( | ||
| opChanges { studyQueues = true }, | ||
| null, | ||
| ) | ||
| } |
|
|
||
| (filesResIds + prefItemsResIds) | ||
| .filterIsInstance<Int>() | ||
| .filter { it != 0 } |
There was a problem hiding this comment.
Why is there sometimes a resource of 0?
It's best to figure this out, rather than ignore something in the test which we don't understand.
Is this 0 a missing resource, or something which was incorrectly loaded?
I think the best option would be to add a log of the count + names of all selected resource IDs, then we know if it's extra or missing.
| val didDynamicA = addDynamicDeck("Deck Dynamic 1") | ||
|
|
||
| val noteEditor = selectContextMenuOptionForActivity(DeckPickerContextMenuOption.ADD_CARD, didA) | ||
| val noteEditor = |
There was a problem hiding this comment.
Please revert all these spacing changes, they make it difficult to understand the change
| equalFirstField(cards[0], reviewer.currentCard!!) | ||
| reviewer.answerCard(Rating.AGAIN) | ||
| advanceRobolectricLooper() | ||
| runUiThreadTasksIncludingDelayedTasks() |
There was a problem hiding this comment.
These appear to be equivalent
fun advanceRobolectricLooper() {
Shadows.shadowOf(Looper.getMainLooper()).runToEndOfTasks()
} public static void runUiThreadTasksIncludingDelayedTasks() {
getShadowMainLooper().runToEndOfTasks();
}|
@david-allison Thank you for your review, I am moving this PR to draft while I work through your feedback and address the necessary changes. I will update you once I am ready and will make the PR open once updates are done. |
Purpose / Description
While working on my PR #20412, I faced failure in JUnitTests (macos run 1) and on reviewing it, I observed that no changes I had made during any of my commits affected the files in which errors were faced and on further reviewing, I realized that these were triggered due to the specific development environment (Linux/Windows dual-boot and non-UTC TimeZone. Hence, I raised the issue #20413. This PR aims to resolve the issue.
Fixes
Fixes #20413
Approach
This change addresses the following three categories of instabilities (all of those reported in the issue #20413):
PrefsSearchBarTest.ktin the directoryAnkiDroid/src/test/java/com/ichi2/anki/preferencesto ignore non-XML indexed items (IDs of 0), which were causingResources$NotFoundException.MockTime.timestampin theMockTime.ktinside directorycommon/src/main/java/com/ichi2/anki/common/timeto use a forced GMT calendar and updatedAlarmManagerServiceTest.ktinside the directoryAnkiDroid/src/test/java/com/ichi2/anki/services/AlarmManagerServiceTest.ktto set a UTC default during execution which prevents assertions from failing in a non-UTC TimeZone.advanceRobolectricLooper()withShadowLooper.runUiThreadTasksIncludingDelayedTasks()inReviewerTest.ktwherever required and addedadvanceRobolectricLooper()where required inDeckPickerTest.kt, both of the files present in the directoryAnkiDroid/src/test/java/com/ichi2/anki. This ensures the full asynchronous chain (Collection -> Scheduler -> WebView) completes before assertions run.How Has This Been Tested?
./gradlew testPlayDebugUnitTestwhich ran successfully on implementing the following changes allowing me to conclude that the changes were made successfully.Learning (optional, can help others)
Checklist
Please, go through these checks before submitting the PR.