mirror of
https://github.com/samsonjs/media.git
synced 2026-04-12 12:25:47 +00:00
MediaControllerWithMediaSessionCompatTest
Fix a race condition making test flaky. PiperOrigin-RevId: 480104467
This commit is contained in:
parent
b0daae72cf
commit
cb3a672508
1 changed files with 10 additions and 1 deletions
|
|
@ -168,6 +168,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||
@Test
|
||||
public void disconnected_byControllerReleaseRightAfterCreated() throws Exception {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<Exception> exception = new AtomicReference<>();
|
||||
MediaController controller =
|
||||
controllerTestRule.createController(
|
||||
session.getSessionToken(),
|
||||
|
|
@ -177,8 +178,16 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||
latch.countDown();
|
||||
}
|
||||
},
|
||||
/* controllerCreationListener= */ MediaController::release);
|
||||
/* controllerCreationListener= */ mediaController -> {
|
||||
// We must release the controller on the app thread.
|
||||
try {
|
||||
threadTestRule.getHandler().postAndSync(() -> mediaController.release());
|
||||
} catch (Exception e) {
|
||||
exception.set(e);
|
||||
}
|
||||
});
|
||||
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||
assertThat(exception.get()).isNull();
|
||||
assertThat(controller.isConnected()).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue