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

Commit 69e5abcb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Resolve flaky statemachine tests"

parents b07b22fb bb06800e
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -668,11 +668,18 @@ public class AvrcpControllerStateMachineTest {
        secondAvrcpStateMachine.start();
        Assert.assertFalse(mAvrcpStateMachine.isActive());

        // Connect device 1 and 2 and verify first one is set as active
        // Connect device 1 and 2 and verify second one is set as active
        setUpConnectedState(true, true);
        secondAvrcpStateMachine.connect(StackEvent.connectionStateChanged(true, true));
        TestUtils.waitForLooperToFinishScheduledTask(mAvrcpStateMachine.getHandler().getLooper());
        Assert.assertTrue(mAvrcpStateMachine.isActive());
        Assert.assertFalse(secondAvrcpStateMachine.isActive());

        secondAvrcpStateMachine.connect(StackEvent.connectionStateChanged(true, true));
        TestUtils.waitForLooperToFinishScheduledTask(mAvrcpStateMachine.getHandler().getLooper());
        TestUtils.waitForLooperToFinishScheduledTask(secondAvrcpStateMachine.getHandler()
                .getLooper());

        Assert.assertFalse(mAvrcpStateMachine.isActive());
        Assert.assertTrue(secondAvrcpStateMachine.isActive());

        // Request the second device to play an item and verify active device switched
        BrowseTree.BrowseNode results = mAvrcpStateMachine.findNode(rootName);
+6 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.Utils;

import org.hamcrest.core.AllOf;
@@ -96,6 +97,7 @@ public class HeadsetClientStateMachineTest {
                new HeadsetClientStateMachine(mHeadsetClientService, mHandlerThread.getLooper(),
                                              mNativeInterface);
        mHeadsetClientStateMachine.start();
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
    }

    @After
@@ -103,6 +105,7 @@ public class HeadsetClientStateMachineTest {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_hfpclient)) {
            return;
        }
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        mHeadsetClientStateMachine.doQuit();
        mHandlerThread.quit();
    }
@@ -292,10 +295,11 @@ public class HeadsetClientStateMachineTest {
                        -1));
        Assert.assertEquals(true, mHeadsetClientStateMachine.getInBandRing());


        // Simulate a new incoming phone call
        StackEvent eventCallStatusUpdated = new StackEvent(StackEvent.EVENT_TYPE_CLIP);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, eventCallStatusUpdated);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        verify(mHeadsetClientService, timeout(STANDARD_WAIT_MILLIS).times(3)).sendBroadcast(
                intentArgument.capture(),
                anyString());
@@ -319,11 +323,11 @@ public class HeadsetClientStateMachineTest {
        StackEvent eventCommandStatus = new StackEvent(StackEvent.EVENT_TYPE_CMD_RESULT);
        eventCommandStatus.valueInt = AT_OK;
        mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, eventCommandStatus);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
        verify(mHeadsetClientService, timeout(QUERY_CURRENT_CALLS_TEST_WAIT_MILLIS).times(4))
                .sendBroadcast(
                intentArgument.capture(),
                anyString());

        // Verify that the new call is being registered with the inBandRing flag set.
        Assert.assertEquals(true,
                ((BluetoothHeadsetClientCall) intentArgument.getValue().getParcelableExtra(