Rearrange condition blocking to ensure Handler thread loops

Without this change, any prepare() operation that requires posting to
the DummyMainThread's handler cannot complete preparation.

PiperOrigin-RevId: 233050367
This commit is contained in:
aquilescanta 2019-02-08 14:33:42 +00:00 committed by Andrew Lewis
parent fd979790f2
commit 891ec2230e
2 changed files with 8 additions and 8 deletions

View file

@ -53,7 +53,7 @@ public final class DummyMainThread {
* Runs the provided {@link Runnable} on the main thread, blocking until execution completes or * Runs the provided {@link Runnable} on the main thread, blocking until execution completes or
* until timeout milliseconds have passed. * until timeout milliseconds have passed.
* *
* @param timeoutMs the maximum time to wait in milliseconds. * @param timeoutMs The maximum time to wait in milliseconds.
* @param runnable The {@link Runnable} to run. * @param runnable The {@link Runnable} to run.
*/ */
public void runOnMainThread(int timeoutMs, final Runnable runnable) { public void runOnMainThread(int timeoutMs, final Runnable runnable) {

View file

@ -187,13 +187,14 @@ public final class MediaPeriodAsserts {
private static TrackGroupArray getTrackGroups(MediaPeriod mediaPeriod) { private static TrackGroupArray getTrackGroups(MediaPeriod mediaPeriod) {
AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>(null); AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>(null);
DummyMainThread dummyMainThread = new DummyMainThread(); DummyMainThread dummyMainThread = new DummyMainThread();
ConditionVariable preparedCondition = new ConditionVariable();
dummyMainThread.runOnMainThread( dummyMainThread.runOnMainThread(
() -> { () -> {
ConditionVariable preparedCondition = new ConditionVariable();
mediaPeriod.prepare( mediaPeriod.prepare(
new Callback() { new Callback() {
@Override @Override
public void onPrepared(MediaPeriod mediaPeriod) { public void onPrepared(MediaPeriod mediaPeriod) {
trackGroupArray.set(mediaPeriod.getTrackGroups());
preparedCondition.open(); preparedCondition.open();
} }
@ -203,13 +204,12 @@ public final class MediaPeriodAsserts {
} }
}, },
/* positionUs= */ 0); /* positionUs= */ 0);
try {
preparedCondition.block();
} catch (InterruptedException e) {
// Ignore.
}
trackGroupArray.set(mediaPeriod.getTrackGroups());
}); });
try {
preparedCondition.block();
} catch (InterruptedException e) {
// Ignore.
}
dummyMainThread.release(); dummyMainThread.release();
return trackGroupArray.get(); return trackGroupArray.get();
} }