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

Commit a7888a59 authored by Leslie Watkins's avatar Leslie Watkins
Browse files

Fix race condition causing flakiness in HfpClientConnectionServiceTest.

Bug: 202869861
Test: atest BluetoothInstrumentationTests --iterations 100
Tag: #stability
Change-Id: I957fdc981e0b324a4086e7d5856a81f882734993
parent 6d0f8fb7
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.hfpclient.connserv;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -270,7 +271,16 @@ public class HfpClientConnectionServiceTest {
        mServiceRule.startService(createServiceIntent());
        InstrumentationRegistry.getTargetContext().sendBroadcast(
                createDeviceConnectedIntent(device));
        assertThat(buildLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();

        buildLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
        long startTime = System.currentTimeMillis();
        while (mHfpClientConnectionService.findBlockForDevice(device) == null) {
            if (System.currentTimeMillis() - startTime > TIMEOUT_MS) {
                assertWithMessage(
                        "Timeout waiting for block to be added to HfpClientConnectionService")
                        .fail();
            }
        }
    }

    private HfpClientDeviceBlock.Factory createDeviceBlockFactoryForTest(