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

test: fail on unhandled exception #16281

Merged
merged 1 commit into from Apr 27, 2024

Conversation

david-allison
Copy link
Member

@david-allison david-allison commented Apr 27, 2024

Purpose / Description

Previously, an unhandled exception would hang, now it fails

Fixes

Approach

Assert no unhandled exceptions are thrown

How Has This Been Tested?

https://github.com/ankidroid/Anki-Android/actions/runs/8859797884

WhiteboardDefaultForegroundColorTest > [1] > testDefaultForegroundColor[1] FAILED
    java.lang.IllegalStateException: unhandled exception
        at com.ichi2.testutils.FailOnUnhandledExceptionRule$apply$1.evaluate(FailOnUnhandledExceptionRule.kt:64)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:588)
        at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$2(SandboxTestRunner.java:290)
        at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:101)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)

        Caused by:
        net.ankiweb.rsdroid.exceptions.BackendInvalidInputException$BackendCollectionAlreadyOpenException: CollectionAlreadyOpen
            at net.ankiweb.rsdroid.exceptions.BackendInvalidInputException$Companion.fromInvalidInputError(BackendInvalidInputException.kt:34)
            at net.ankiweb.rsdroid.BackendException$Companion.fromError(BackendException.kt:114)
            at net.ankiweb.rsdroid.BackendKt.unpackResult(Backend.kt:271)
            at net.ankiweb.rsdroid.BackendKt.access$unpackResult(Backend.kt:1)
            at net.ankiweb.rsdroid.Backend$runMethodRaw$1.invoke(Backend.kt:118)
            at net.ankiweb.rsdroid.Backend$runMethodRaw$1.invoke(Backend.kt:117)
            at net.ankiweb.rsdroid.Backend.withBackend(Backend.kt:131)
            at net.ankiweb.rsdroid.Backend.runMethodRaw(Backend.kt:117)
            at anki.backend.GeneratedBackend.openCollectionRaw(GeneratedBackend.kt:102)
            at anki.backend.GeneratedBackend.openCollection(GeneratedBackend.kt:109)
            at net.ankiweb.rsdroid.Backend.openCollection(Backend.kt:98)
            at net.ankiweb.rsdroid.Backend.openCollection(Backend.kt:57)
            at com.ichi2.libanki.Storage.openDB$AnkiDroid_playDebug(Storage.kt:52)
            at com.ichi2.libanki.Collection.reopen(Collection.kt:206)
            at com.ichi2.libanki.Collection.reopen$default(Collection.kt:203)
            at com.ichi2.libanki.Collection.<init>(Collection.kt:138)
            at com.ichi2.libanki.Storage.collection(Storage.kt:40)
            at com.ichi2.anki.CollectionManager.ensureOpenInner(CollectionManager.kt:230)
            at com.ichi2.anki.CollectionManager.access$ensureOpenInner(CollectionManager.kt:39)
            at com.ichi2.anki.CollectionManager$withCol$2.invoke(CollectionManager.kt:101)
            at com.ichi2.anki.CollectionManager$withCol$2.invoke(CollectionManager.kt:100)
            at com.ichi2.anki.CollectionManager$withQueue$2.invokeSuspend(CollectionManager.kt:86)
            at app//kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
            at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
            at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:65)
            at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:[371](https://github.com/ankidroid/Anki-Android/actions/runs/8859797884/job/24330353482?pr=16281#step:8:373))
            at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
            at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:21)
            at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:88)
            at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
            at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
            at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
            at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
            at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
            at com.ichi2.anki.Reviewer.addFlags(Reviewer.kt:659)
            at com.ichi2.anki.Reviewer.onCreateOptionsMenu(Reviewer.kt:676)
            at android.app.Activity.$$robo$$android_app_Activity$onCreatePanelMenu(Activity.java:4343)
            at android.app.Activity.onCreatePanelMenu(Activity.java)
            at androidx.activity.ComponentActivity.onCreatePanelMenu(ComponentActivity.java:520)
            at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:94)
            at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu(AppCompatDelegateImpl.java:3442)
            at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:458)
            at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:58)
            at android.os.Handler.$$robo$$android_os_Handler$handleCallback(Handler.java:942)
            at android.os.Handler.handleCallback(Handler.java)
            at android.os.Handler.$$robo$$android_os_Handler$dispatchMessage(Handler.java:99)
            at android.os.Handler.dispatchMessage(Handler.java)
            at org.robolectric.shadows.ShadowPausedLooper$IdlingRunnable.doRun(ShadowPausedLooper.java:573)
            at org.robolectric.shadows.ShadowPausedLooper$ControlRunnable.run(ShadowPausedLooper.java:536)
            at org.robolectric.shadows.ShadowPausedLooper.executeOnLooper(ShadowPausedLooper.java:629)
            at org.robolectric.shadows.ShadowPausedLooper.idle(ShadowPausedLooper.java:104)
            at org.robolectric.shadows.ShadowPausedLooper.idleIfPaused(ShadowPausedLooper.java:177)
            at org.robolectric.android.controller.ActivityController.visible(ActivityController.java:232)
            at com.ichi2.anki.RobolectricTest$Companion.startActivityNormallyOpenCollectionWithIntent(RobolectricTest.kt:284)
            at com.ichi2.anki.RobolectricTest.startActivityNormallyOpenCollectionWithIntent(RobolectricTest.kt)
            at com.ichi2.anki.RobolectricTest.startActivityNormallyOpenCollectionWithIntent$AnkiDroid_playDebugUnitTest(RobolectricTest.kt:342)
            at com.ichi2.anki.WhiteboardDefaultForegroundColorTest.getForegroundColor(WhiteboardDefaultForegroundColorTest.kt:43)
            at com.ichi2.anki.WhiteboardDefaultForegroundColorTest.testDefaultForegroundColor(WhiteboardDefaultForegroundColorTest.kt:38)
TemplatePreviewerViewModelTest > getCurrentTabIndex returns the correct tab if the first cloze isn't 1 and ord isn't 0 FAILED
    kotlinx.coroutines.test.UncaughtExceptionsBeforeTest: There were uncaught exceptions before the test started. Please avoid this, as such exceptions are also reported in a platform-dependent manner so that they are not lost.
        at kotlinx.coroutines.test.TestScopeImpl.enter(TestScope.kt:239)
        at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:309)
        at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
        at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:168)
        at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
        at com.ichi2.testutils.TestClass.runTest(TestClass.kt:238)
        at com.ichi2.testutils.TestClass.runTest$default(TestClass.kt:227)
        at com.ichi2.anki.previewer.TemplatePreviewerViewModelTest.runClozeTest(TemplatePreviewerViewModelTest.kt:61)
        at com.ichi2.anki.previewer.TemplatePreviewerViewModelTest.getCurrentTabIndex returns the correct tab if the first cloze isn't 1 and ord isn't 0(TemplatePreviewerViewModelTest.kt:38)

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added Needs Review Needs Author Reply Waiting for a reply from the original author labels Apr 27, 2024
@david-allison

This comment was marked as resolved.

Previously, an unhandled exception would hang

Issue 16253
@david-allison

This comment was marked as resolved.

@david-allison

This comment was marked as resolved.

@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Apr 27, 2024
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Nice - I believe the ACRA tests are mostly configuration oriented and there is no testing nor reliance on the state of the exception-handling chain in test, so this looks like a pretty clean fix. Going with it

@mikehardy mikehardy added this pull request to the merge queue Apr 27, 2024
Merged via the queue into ankidroid:main with commit 909867c Apr 27, 2024
5 checks passed
@github-actions github-actions bot added this to the 2.18 release milestone Apr 27, 2024
@david-allison david-allison deleted the flaky-test-rule branch April 27, 2024 17:34
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.

None yet

2 participants