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

Commit a186a3f1 authored by Michal Belusiak's avatar Michal Belusiak
Browse files

ActiveDeviceManagerTest: Dispatch tasks before verify

Wait for looper to finish scheduled task on each post call when
there is any verify after it. We can remove timeouts in verification.

Fixed a lot of rare flakiness.

Fixed a2dpAndLeAudioConnectedThenLeAudioDisconnected_fallbackToA2dp
which sometimes ends up before tasks were executed, which caused
wrong behavior on getLeadDevice mock.

Speeds up tests execution more than two times.

Bug: 321202011
Test: atest ActiveDeviceManagerTest --rerun-until-failure 1000
Flag: Exempt, tests changes only
Change-Id: I6eb9f146a6c3408cdafe2b59f69e8aad53ccd3c0
parent f059ee57
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -160,6 +160,9 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    private BluetoothDevice mClassicDeviceToBeActivated = null;
    private BluetoothDevice mClassicDeviceNotToBeActivated = null;

    // Timeout for state machine thread join, to prevent potential ANR.
    private static final int SM_THREAD_JOIN_TIMEOUT_MS = 1000;

    @Override
    public void onBluetoothStateChange(int prevState, int newState) {
        mHandler.post(() -> handleAdapterStateChanged(newState));
@@ -849,7 +852,12 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerAudioDeviceCallback);
        mAdapterService.unregisterBluetoothStateCallback(this);
        if (mHandlerThread != null) {
            mHandlerThread.quit();
            mHandlerThread.quitSafely();
            try {
                mHandlerThread.join(SM_THREAD_JOIN_TIMEOUT_MS);
            } catch (InterruptedException e) {
                // Do not rethrow as we are shutting down anyway
            }
            mHandlerThread = null;
        }
        resetState();
+272 −210

File changed.

Preview size limit exceeded, changes collapsed.