Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b724113 authored by Angela Wang's avatar Angela Wang
Browse files

Fix: Resolve crash from delayed main thread tasks

A delayed message posted to the main thread can cause a crash if it's processed after a test has completed. This change adds a cleanup step to clear all pending tasks on the main thread's handler in the test tear-down. This prevents test pollution and ensures a clean, isolated environment for each test run.

Flag: EXEMPT fix flaky test
Bug: 443688194
Test: atest HearingDevicesDialogDelegateTest KeyGestureDialogInteractorTest
Change-Id: I57373af02d57d0e171b52c923d62a6a66c9232e3
parent 6e3a287b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -477,6 +477,11 @@ public class HearingDevicesDialogDelegateTest extends SysuiTestCase {

    @After
    public void reset() {
        // Clears all pending messages and callbacks from the main thread's Handler to prevent
        // unintended side effects or crashes in subsequent tests.
        mContext.getMainThreadHandler().removeCallbacksAndMessages(null);
        mTestableLooper.processAllMessages();

        if (mDialogDelegate != null) {
            mDialogDelegate = null;
        }