Commit 78fe1afa by christosts Committed by Ian Baker

Fix flaky unit tests

PiperOrigin-RevId: 290910992
parent d64388a0
...@@ -290,11 +290,14 @@ public class DedicatedThreadAsyncMediaCodecAdapterTest { ...@@ -290,11 +290,14 @@ public class DedicatedThreadAsyncMediaCodecAdapterTest {
AtomicInteger onCodecStartCount = new AtomicInteger(0); AtomicInteger onCodecStartCount = new AtomicInteger(0);
adapter.setCodecStartRunnable(() -> onCodecStartCount.incrementAndGet()); adapter.setCodecStartRunnable(() -> onCodecStartCount.incrementAndGet());
adapter.start(); adapter.start();
// Grab reference to Looper before shutting down the adapter otherwise handlerThread.getLooper()
// might return null.
Looper looper = handlerThread.getLooper();
adapter.flush(); adapter.flush();
adapter.shutdown(); adapter.shutdown();
// Wait until all tasks have been handled. // Wait until all tasks have been handled.
Shadows.shadowOf(handlerThread.getLooper()).idle(); Shadows.shadowOf(looper).idle();
// Only adapter.start() calls onCodecStart. // Only adapter.start() calls onCodecStart.
assertThat(onCodecStartCount.get()).isEqualTo(1); assertThat(onCodecStartCount.get()).isEqualTo(1);
} }
......
...@@ -290,10 +290,13 @@ public class MultiLockAsyncMediaCodecAdapterTest { ...@@ -290,10 +290,13 @@ public class MultiLockAsyncMediaCodecAdapterTest {
AtomicInteger codecStartCalls = new AtomicInteger(0); AtomicInteger codecStartCalls = new AtomicInteger(0);
adapter.setCodecStartRunnable(() -> codecStartCalls.incrementAndGet()); adapter.setCodecStartRunnable(() -> codecStartCalls.incrementAndGet());
adapter.start(); adapter.start();
// Grab reference to Looper before shutting down the adapter otherwise handlerThread.getLooper()
// might return null.
Looper looper = handlerThread.getLooper();
adapter.flush(); adapter.flush();
adapter.shutdown(); adapter.shutdown();
Shadows.shadowOf(handlerThread.getLooper()).idle(); Shadows.shadowOf(looper).idle();
// Only adapter.start() called codec#start() // Only adapter.start() called codec#start()
assertThat(codecStartCalls.get()).isEqualTo(1); assertThat(codecStartCalls.get()).isEqualTo(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment