mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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
|
@Test
|
||||||
public void disconnected_byControllerReleaseRightAfterCreated() throws Exception {
|
public void disconnected_byControllerReleaseRightAfterCreated() throws Exception {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
AtomicReference<Exception> exception = new AtomicReference<>();
|
||||||
MediaController controller =
|
MediaController controller =
|
||||||
controllerTestRule.createController(
|
controllerTestRule.createController(
|
||||||
session.getSessionToken(),
|
session.getSessionToken(),
|
||||||
|
|
@ -177,8 +178,16 @@ public class MediaControllerWithMediaSessionCompatTest {
|
||||||
latch.countDown();
|
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(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
|
assertThat(exception.get()).isNull();
|
||||||
assertThat(controller.isConnected()).isFalse();
|
assertThat(controller.isConnected()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue