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

Commit 9b246eaf authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge "Add waiting timeout in test to fix flakiness" into main am: 51bfbbfc

parents dc711527 51bfbbfc
Loading
Loading
Loading
Loading
+42 −32
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -84,7 +83,7 @@ import java.util.concurrent.LinkedBlockingQueue;
@RunWith(AndroidJUnit4.class)
public class HeadsetServiceAndStateMachineTest {
    private static final String TAG = "HeadsetServiceAndStateMachineTest";
    private static final int ASYNC_CALL_TIMEOUT_MILLIS = 250;
    private static final int ASYNC_CALL_TIMEOUT_MILLIS = 500;
    private static final int START_VR_TIMEOUT_MILLIS = 1000;
    private static final int START_VR_TIMEOUT_WAIT_MILLIS = START_VR_TIMEOUT_MILLIS * 3 / 2;
    private static final int STATE_CHANGE_TIMEOUT_MILLIS = 1000;
@@ -98,8 +97,6 @@ public class HeadsetServiceAndStateMachineTest {
    private Context mTargetContext;
    private HeadsetService mHeadsetService;
    private BluetoothAdapter mAdapter;
    private ArgumentCaptor<HeadsetStateMachine> mStateMachineArgument =
            ArgumentCaptor.forClass(HeadsetStateMachine.class);
    private HashSet<BluetoothDevice> mBondedDevices = new HashSet<>();
    private final BlockingQueue<Intent> mConnectionStateChangedQueue = new LinkedBlockingQueue<>();
    private final BlockingQueue<Intent> mActiveDeviceChangedQueue = new LinkedBlockingQueue<>();
@@ -350,9 +347,11 @@ public class HeadsetServiceAndStateMachineTest {
        unbondIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        InstrumentationRegistry.getTargetContext().sendBroadcast(unbondIntent);
        // Check that the state machine is actually destroyed
        verify(mObjectsFactory, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).destroyStateMachine(
                mStateMachineArgument.capture());
        Assert.assertEquals(device, mStateMachineArgument.getValue().getDevice());
        ArgumentCaptor<HeadsetStateMachine> stateMachineArgument =
                ArgumentCaptor.forClass(HeadsetStateMachine.class);
        verify(mObjectsFactory, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .destroyStateMachine(stateMachineArgument.capture());
        Assert.assertEquals(device, stateMachineArgument.getValue().getDevice());
    }

    /**
@@ -407,10 +406,11 @@ public class HeadsetServiceAndStateMachineTest {
        waitAndVerifyConnectionStateIntent(ASYNC_CALL_TIMEOUT_MILLIS, device,
                BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTED);
        // Check that the state machine is destroyed after another async call
        verify(mObjectsFactory, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).destroyStateMachine(
                mStateMachineArgument.capture());
        Assert.assertEquals(device, mStateMachineArgument.getValue().getDevice());

        ArgumentCaptor<HeadsetStateMachine> stateMachineArgument =
                ArgumentCaptor.forClass(HeadsetStateMachine.class);
        verify(mObjectsFactory, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .destroyStateMachine(stateMachineArgument.capture());
        Assert.assertEquals(device, stateMachineArgument.getValue().getDevice());
    }

    /**
@@ -672,7 +672,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        startVoiceRecognitionFromHf(device);
    }
@@ -696,7 +696,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        startVoiceRecognitionFromHf(device);
        // Stop voice recognition
@@ -731,7 +731,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        HeadsetStackEvent startVrEvent =
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_VR_STATE_CHANGED,
@@ -764,7 +764,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        HeadsetStackEvent startVrEvent =
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_VR_STATE_CHANGED,
@@ -797,7 +797,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        startVoiceRecognitionFromAg();
    }
@@ -871,7 +871,7 @@ public class HeadsetServiceAndStateMachineTest {
        Assert.assertTrue(mHeadsetService.setActiveDevice(device));
        verify(mNativeInterface).setActiveDevice(device);
        Assert.assertEquals(device, mHeadsetService.getActiveDevice());
        verify(mNativeInterface).sendBsir(eq(device), eq(true));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBsir(eq(device), eq(true));
        // Start voice recognition
        startVoiceRecognitionFromAg();
        // Stop voice recognition
@@ -921,9 +921,12 @@ public class HeadsetServiceAndStateMachineTest {
        BluetoothDevice deviceB = TestUtils.getTestDevice(mAdapter, 1);
        connectTestDevice(deviceB);
        InOrder inOrder = inOrder(mNativeInterface);
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(false));
        // Set active device to device B
        Assert.assertTrue(mHeadsetService.setActiveDevice(deviceB));
        verify(mNativeInterface).setActiveDevice(deviceB);
@@ -971,14 +974,17 @@ public class HeadsetServiceAndStateMachineTest {
    @Test
    public void testVoiceRecognition_MultiHfInitiatedSwitchActiveDeviceReplyWrongHfSuccess() {
        // Connect two devices
        InOrder inOrder = inOrder(mNativeInterface);
        BluetoothDevice deviceA = TestUtils.getTestDevice(mAdapter, 0);
        connectTestDevice(deviceA);
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(true));
        BluetoothDevice deviceB = TestUtils.getTestDevice(mAdapter, 1);
        connectTestDevice(deviceB);
        InOrder inOrder = inOrder(mNativeInterface);
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(false));
        // Set active device to device B
        Assert.assertTrue(mHeadsetService.setActiveDevice(deviceB));
        verify(mNativeInterface).setActiveDevice(deviceB);
@@ -1024,7 +1030,6 @@ public class HeadsetServiceAndStateMachineTest {
     * Reference: Section 4.25, Page 64/144 of HFP 1.7.1 specification
     */
    @Test
    @Ignore("b/271351629")
    public void testVoiceRecognition_MultiAgInitiatedSuccess() {
        // Connect two devices
        BluetoothDevice deviceA = TestUtils.getTestDevice(mAdapter, 0);
@@ -1032,9 +1037,12 @@ public class HeadsetServiceAndStateMachineTest {
        BluetoothDevice deviceB = TestUtils.getTestDevice(mAdapter, 1);
        connectTestDevice(deviceB);
        InOrder inOrder = inOrder(mNativeInterface);
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(false));
        // Set active device to device B
        Assert.assertTrue(mHeadsetService.setActiveDevice(deviceB));
        verify(mNativeInterface).setActiveDevice(deviceB);
@@ -1066,7 +1074,6 @@ public class HeadsetServiceAndStateMachineTest {
     * Reference: Section 4.25, Page 64/144 of HFP 1.7.1 specification
     */
    @Test
    @Ignore("b/271351629")
    public void testVoiceRecognition_MultiAgInitiatedDeviceNotActive() {
        // Connect two devices
        BluetoothDevice deviceA = TestUtils.getTestDevice(mAdapter, 0);
@@ -1074,9 +1081,12 @@ public class HeadsetServiceAndStateMachineTest {
        BluetoothDevice deviceB = TestUtils.getTestDevice(mAdapter, 1);
        connectTestDevice(deviceB);
        InOrder inOrder = inOrder(mNativeInterface);
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface).sendBsir(eq(deviceA), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(true));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceB), eq(false));
        inOrder.verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                .sendBsir(eq(deviceA), eq(false));
        // Set active device to device B
        Assert.assertTrue(mHeadsetService.setActiveDevice(deviceB));
        verify(mNativeInterface).setActiveDevice(deviceB);