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

Commit a8b20b31 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fix flaky test

Test was flaky because the messages were posted in main looper (that is
not injected) and needed to be flushed.

Test: this test
Fixes: 132420431
Change-Id: Ie0765b574f3b1425a4d65ca13c3a1ae5eaf53b5c
parent 1ff27fa8
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -203,7 +203,8 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
    }

    @Test
    public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection() {
    public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection()
            throws Exception {
        BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
        mBluetoothControllerImpl.addCallback(callback);

@@ -215,6 +216,16 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
        reset(callback);
        mBluetoothControllerImpl.onAclConnectionStateChanged(device,
                BluetoothProfile.STATE_CONNECTED);

        // Grab the main looper, we'll need it later.
        TestableLooper mainLooper = new TestableLooper(Looper.getMainLooper());

        try {
            mTestableLooper.processAllMessages();
            mainLooper.processAllMessages();
        } finally {
            mainLooper.destroy();
        }
        assertTrue(mBluetoothControllerImpl.isBluetoothConnected());
        verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean());
    }