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

Commit 3d5bc263 authored by Matías Hernández's avatar Matías Hernández
Browse files

Deflake NotificationTemplateViewWrapperTest

Test passes 100% in isolation (and is quite simple) but is extremely flaky when run in the suite. So I'm guessing it's caused by the sUiOffloadThread being cached before it's set to the testable one (on the first usage from somewhere else). So force a refresh here.

Fixes: 444085872
Fixes: 443062831
Test: atest NotificationTemplateViewWrapperTest
Flag: TEST_ONLY
Change-Id: Iab00d848e79377e419e9c8d369f5e70107392de7
parent 78b656af
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.android.internal.annotations.VisibleForTesting;
import androidx.annotation.VisibleForTesting;

import com.android.internal.util.ContrastColorUtil;
import com.android.internal.widget.NotificationActionListLayout;
import com.android.systemui.Dependency;
@@ -454,6 +455,11 @@ public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapp
            return sUiOffloadThread;
        }

        @VisibleForTesting(otherwise = VisibleForTesting.NONE)
        static void resetUiOffloadThread() {
            sUiOffloadThread = null;
        }

        private final View mView;
        private final Consumer<PendingIntent> mOnCancelledCallback;

+14 −10
Original line number Diff line number Diff line
@@ -67,8 +67,10 @@ class NotificationTemplateViewWrapperTest : SysuiTestCase() {
        // Use main thread instead of UI offload thread to fix flakes.
        mDependency.injectTestDependency(
            UiOffloadThread::class.java,
            TestUiOffloadThread(looper.looper)
            TestUiOffloadThread(looper.looper),
        )
        // Clear statically-cached data, in case this class was used before.
        ActionPendingIntentCancellationHandler.resetUiOffloadThread()

        row = kosmos.createRow()
        // Some code in the view iterates through parents so we need some extra containers around
@@ -178,12 +180,14 @@ class NotificationTemplateViewWrapperTest : SysuiTestCase() {
    @Test
    fun actionViewDetached_pendingIntentListenersDeregistered() {
        val pi =
            Mockito.spy(PendingIntent.getActivity(
            Mockito.spy(
                PendingIntent.getActivity(
                    mContext,
                    System.currentTimeMillis().toInt(),
                    Intent(Intent.ACTION_VIEW),
                PendingIntent.FLAG_IMMUTABLE
            ))
                    PendingIntent.FLAG_IMMUTABLE,
                )
            )
        val mockView = Mockito.mock(View::class.java)
        val handler = ActionPendingIntentCancellationHandler(pi, mockView, null)

@@ -204,7 +208,7 @@ class NotificationTemplateViewWrapperTest : SysuiTestCase() {
                mContext,
                System.currentTimeMillis().toInt(),
                Intent(Intent.ACTION_VIEW),
                PendingIntent.FLAG_IMMUTABLE
                PendingIntent.FLAG_IMMUTABLE,
            )
        val spy = Mockito.spy(pi)
        val action = createActionWithPendingIntent(spy)
@@ -224,7 +228,7 @@ class NotificationTemplateViewWrapperTest : SysuiTestCase() {
                mContext,
                System.currentTimeMillis().toInt(),
                Intent(Intent.ACTION_ALARM_CHANGED),
                PendingIntent.FLAG_IMMUTABLE
                PendingIntent.FLAG_IMMUTABLE,
            )
        action.setTagInternal(R.id.pending_intent_tag, newPi)
        wrapper.onContentUpdated(row)
@@ -246,7 +250,7 @@ class NotificationTemplateViewWrapperTest : SysuiTestCase() {
                mContext,
                System.currentTimeMillis().toInt(),
                Intent(Intent.ACTION_VIEW),
                PendingIntent.FLAG_IMMUTABLE
                PendingIntent.FLAG_IMMUTABLE,
            )
        return createActionWithPendingIntent(pi)
    }