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

Commit 50fe0f84 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Add timeouts to ComputerControlExtensionsTest callbacks.

The tests now wait for a short duration for the session creation/failure callbacks to be invoked, addressing potential flakiness due to asynchronous operations.

Fix: 438063338
Test: presubmit
Flag: EXEMPT test improvement
Change-Id: Ib39ed670cf8e78b229afaba455726b5f57a4f077
parent 79c374eb
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertThrows;
@@ -52,6 +53,7 @@ import java.util.concurrent.Executors;
@RequiresFlagsEnabled(android.companion.virtualdevice.flags.Flags.FLAG_COMPUTER_CONTROL_ACCESS)
@RunWith(AndroidJUnit4.class)
public class ComputerControlExtensionsTest {
    private static final int CALLBACK_TIMEOUT_MS = 1_000;
    private static final int DISPLAY_DPI = 100;
    private static final int DISPLAY_HEIGHT = 200;
    private static final int DISPLAY_WIDTH = 300;
@@ -123,7 +125,7 @@ public class ComputerControlExtensionsTest {
    }

    @Test
    public void requestSession_withNullParams_throwsException() {
    public void requestSession_withNullParams_throwsNullPointerException() {
        mContext.setMockPackageManager(mPackageManager);

        when(mPackageManager.hasSystemFeature(
@@ -136,7 +138,7 @@ public class ComputerControlExtensionsTest {
    }

    @Test
    public void requestSession_withNullExecutor_throwsException() {
    public void requestSession_withNullExecutor_throwsNullPointerException() {
        mContext.setMockPackageManager(mPackageManager);

        when(mPackageManager.hasSystemFeature(
@@ -149,7 +151,7 @@ public class ComputerControlExtensionsTest {
    }

    @Test
    public void requestSession_withNullCallback_throwsException() {
    public void requestSession_withNullCallback_throwsNullPointerException() {
        mContext.setMockPackageManager(mPackageManager);

        when(mPackageManager.hasSystemFeature(
@@ -198,7 +200,7 @@ public class ComputerControlExtensionsTest {
                createParams(), Executors.newSingleThreadExecutor(), mSessionCallback);

        verify(mIVirtualDeviceManager).requestComputerControlSession(any(), any(), any());
        verify(mSessionCallback).onSessionCreated(any());
        verify(mSessionCallback, timeout(CALLBACK_TIMEOUT_MS)).onSessionCreated(any());
    }

    @Test
@@ -222,7 +224,7 @@ public class ComputerControlExtensionsTest {
                createParams(), Executors.newSingleThreadExecutor(), mSessionCallback);

        verify(mIVirtualDeviceManager).requestComputerControlSession(any(), any(), any());
        verify(mSessionCallback).onSessionCreationFailed(ERROR_CODE);
        verify(mSessionCallback, timeout(CALLBACK_TIMEOUT_MS)).onSessionCreationFailed(ERROR_CODE);
    }

    private ComputerControlSession.Params createParams() {