De-flake new test for ProgressiveMediaSource.suppressPrepareError

This test was added in b3290eff10

#cherrypick

PiperOrigin-RevId: 686918104
This commit is contained in:
ibaker 2024-10-17 08:08:42 -07:00 committed by Copybara-Service
parent 49dec5db8b
commit 64e0397811

View file

@ -19,6 +19,7 @@ import static androidx.media3.test.utils.robolectric.RobolectricUtil.DEFAULT_TIM
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.os.SystemClock;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.common.Timeline; import androidx.media3.common.Timeline;
@ -154,6 +155,12 @@ public class ProgressiveMediaSourceTest {
CountDownLatch preparedLatch = CountDownLatch preparedLatch =
mediaSourceTestRunner.preparePeriod(mediaPeriod, /* positionUs= */ 0); mediaSourceTestRunner.preparePeriod(mediaPeriod, /* positionUs= */ 0);
assertThat(loadErrorReported.await(DEFAULT_TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(loadErrorReported.await(DEFAULT_TIMEOUT_MS, MILLISECONDS)).isTrue();
// Call maybeThrowPrepareError() in a loop until preparation completes (preparation is not
// unblocked until the error is caught and suppressed inside maybeThrowPrepareError()). This
// mimics the behaviour of ExoPlayerImplInternal which calls maybeThrowPrepareError() on
// un-prepared MediaPeriods on every doSomeWork() iteration.
long startTime = SystemClock.elapsedRealtime();
do {
AtomicReference<Throwable> prepareError = new AtomicReference<>(); AtomicReference<Throwable> prepareError = new AtomicReference<>();
mediaSourceTestRunner.runOnPlaybackThread( mediaSourceTestRunner.runOnPlaybackThread(
() -> { () -> {
@ -164,6 +171,8 @@ public class ProgressiveMediaSourceTest {
} }
}); });
assertThat(prepareError.get()).isNull(); assertThat(prepareError.get()).isNull();
} while (preparedLatch.getCount() > 0
&& (SystemClock.elapsedRealtime() - startTime) < DEFAULT_TIMEOUT_MS);
assertThat(preparedLatch.await(DEFAULT_TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(preparedLatch.await(DEFAULT_TIMEOUT_MS, MILLISECONDS)).isTrue();
mediaSourceTestRunner.releasePeriod(mediaPeriod); mediaSourceTestRunner.releasePeriod(mediaPeriod);