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

Commit 67cc6df2 authored by Ben's avatar Ben
Browse files

BumbleBluetoothTests: Improve directConnectGattAfterClose

Reduce the flakyness of GattClientTest#directConnectGattAfterClose
by only reconnecting once (instead of 10 times) and ensuring the
second gatt connection disconnects before the end of the test.

Bug: 322506814
Flag: TEST_ONLY
Test: atest BumbleBluetoothTests:android.bluetooth.GattClientTest
Change-Id: I221291d49f6c14e3e3652288f35d4dcaa095415d
parent 3a66e424
Loading
Loading
Loading
Loading
+17 −20
Original line number Original line Diff line number Diff line
@@ -80,7 +80,6 @@ public class GattClientTest {
                mAdapter.getRemoteLeDevice(
                mAdapter.getRemoteLeDevice(
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);


        for (int i = 0; i < 10; i++) {
        BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
        BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
        BluetoothGatt gatt = device.connectGatt(mContext, false, gattCallback);
        BluetoothGatt gatt = device.connectGatt(mContext, false, gattCallback);
        gatt.close();
        gatt.close();
@@ -93,16 +92,14 @@ public class GattClientTest {
        BluetoothGatt gatt2 = device.connectGatt(mContext, false, gattCallback2);
        BluetoothGatt gatt2 = device.connectGatt(mContext, false, gattCallback2);
        verify(gattCallback2, timeout(1000))
        verify(gattCallback2, timeout(1000))
                .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_CONNECTED));
                .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_CONNECTED));
            gatt2.close();
        disconnectAndWaitDisconnection(gatt2, gattCallback2);


            // After reconnecting with the second set of callback, check that nothing happened on
        // After reconnecting, verify the first callback was not invoked.
            // the first set of callback
        Collection<Invocation> invocationsAfterSomeTimes =
        Collection<Invocation> invocationsAfterSomeTimes =
                mockingDetails(gattCallback).getInvocations();
                mockingDetails(gattCallback).getInvocations();
        int numberOfCallsAfterSomeTimes = invocationsAfterSomeTimes.size();
        int numberOfCallsAfterSomeTimes = invocationsAfterSomeTimes.size();
        assertThat(numberOfCallsAfterSomeTimes).isEqualTo(numberOfCalls);
        assertThat(numberOfCallsAfterSomeTimes).isEqualTo(numberOfCalls);
    }
    }
    }


    @Test
    @Test
    public void fullGattClientLifecycle() throws Exception {
    public void fullGattClientLifecycle() throws Exception {