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

Commit 4ee2d352 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Fix Mockito flakiness when paired with Parameterized runner

Mockito throwing stubbing exceptions when paired with parameterized
junit runner in ShortcutLoggingTests. Make PWM spy() lenient and
add wait statement to end all runnables before starting more
stubbing in ShortcutLoggingTests.

Test: atest ShortcutLoggingTests
Bug: 293273386
Change-Id: I9f96e3a53423d14259c751b49970277709e2738f
parent a3411369
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -19,8 +19,7 @@ package com.android.server.policy;
import android.platform.test.annotations.Presubmit;
import android.view.KeyEvent;

import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;

import com.android.internal.annotations.Keep;
import com.android.server.input.KeyboardMetricsCollector.KeyboardLogEvent;
@@ -33,7 +32,7 @@ import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

@Presubmit
@LargeTest
@MediumTest
@RunWith(JUnitParamsRunner.class)
public class ShortcutLoggingTests extends ShortcutKeyTestBase {

@@ -223,7 +222,7 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {

    @Before
    public void setUp() {
        setUpPhoneWindowManager();
        setUpPhoneWindowManager(/*supportSettingsUpdate*/ true);
        mPhoneWindowManager.overrideKeyEventSource(VENDOR_ID, PRODUCT_ID);
        mPhoneWindowManager.overrideLaunchHome();
        mPhoneWindowManager.overrideSearchKeyBehavior(
@@ -235,7 +234,6 @@ public class ShortcutLoggingTests extends ShortcutKeyTestBase {
    }

    @Test
    @FlakyTest(bugId = 293273386)
    @Parameters(method = "shortcutTestArguments")
    public void testShortcuts(String testName, int[] testKeys, KeyboardLogEvent expectedLogEvent,
            int expectedKey, int expectedModifierState) {
+3 −2
Original line number Diff line number Diff line
@@ -185,11 +185,10 @@ class TestPhoneWindowManager {
        mHandler = new Handler(mHandlerThread.getLooper());
        mContext = mockingDetails(context).isSpy() ? context : spy(context);
        mHandler.runWithScissors(() -> setUp(supportSettingsUpdate),  0 /* timeout */);
        waitForIdle();
    }

    private void setUp(boolean supportSettingsUpdate) {
        mPhoneWindowManager = spy(new PhoneWindowManager());

        // Use stubOnly() to reduce memory usage if it doesn't need verification.
        final MockSettings spyStubOnly = withSettings().stubOnly()
                .defaultAnswer(CALLS_REAL_METHODS);
@@ -200,6 +199,8 @@ class TestPhoneWindowManager {
                .strictness(Strictness.LENIENT)
                .startMocking();

        mPhoneWindowManager = spy(new PhoneWindowManager());

        doReturn(mWindowManagerInternal).when(
                () -> LocalServices.getService(eq(WindowManagerInternal.class)));
        doReturn(mActivityManagerInternal).when(