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

Commit cdc742dc authored by Leslie Watkins's avatar Leslie Watkins Committed by Gerrit Code Review
Browse files

Merge "Fix race condition causing flakiness in HfpClientConnectionServiceTest."

parents a8f111e2 a7888a59
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(