Fix flaky unit tests
PiperOrigin-RevId: 290910992
This commit is contained in:
parent
d64388a075
commit
78fe1afa85
@ -290,11 +290,14 @@ public class DedicatedThreadAsyncMediaCodecAdapterTest {
|
||||
AtomicInteger onCodecStartCount = new AtomicInteger(0);
|
||||
adapter.setCodecStartRunnable(() -> onCodecStartCount.incrementAndGet());
|
||||
adapter.start();
|
||||
// Grab reference to Looper before shutting down the adapter otherwise handlerThread.getLooper()
|
||||
// might return null.
|
||||
Looper looper = handlerThread.getLooper();
|
||||
adapter.flush();
|
||||
adapter.shutdown();
|
||||
|
||||
// Wait until all tasks have been handled.
|
||||
Shadows.shadowOf(handlerThread.getLooper()).idle();
|
||||
Shadows.shadowOf(looper).idle();
|
||||
// Only adapter.start() calls onCodecStart.
|
||||
assertThat(onCodecStartCount.get()).isEqualTo(1);
|
||||
}
|
||||
|
@ -290,10 +290,13 @@ public class MultiLockAsyncMediaCodecAdapterTest {
|
||||
AtomicInteger codecStartCalls = new AtomicInteger(0);
|
||||
adapter.setCodecStartRunnable(() -> codecStartCalls.incrementAndGet());
|
||||
adapter.start();
|
||||
// Grab reference to Looper before shutting down the adapter otherwise handlerThread.getLooper()
|
||||
// might return null.
|
||||
Looper looper = handlerThread.getLooper();
|
||||
adapter.flush();
|
||||
adapter.shutdown();
|
||||
|
||||
Shadows.shadowOf(handlerThread.getLooper()).idle();
|
||||
Shadows.shadowOf(looper).idle();
|
||||
// Only adapter.start() called codec#start()
|
||||
assertThat(codecStartCalls.get()).isEqualTo(1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user