Deflake BubbleBarViewAnimatorTest
Fix an issue where we were verifying the status of the animator on the
test thread, which may have been modified on the main thread.
100x runs: https://android-build.corp.google.com/abtd/run/L42700030003806035/
Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT
Fixes: 339437686
Test: abtd link above
Change-Id: I7e0d67e6ca4b2f905ff80f317355d8d5ed0a912b
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
index 2bcfa3f..ee5786a 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt
@@ -173,7 +173,7 @@
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
PhysicsAnimatorTestUtils.blockUntilFirstAnimationFrameWhereTrue(handleAnimator) { true }
- assertThat(handleAnimator.isRunning()).isTrue()
+ handleAnimator.assertIsRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isTrue()
// verify the hide bubble animation is pending
assertThat(animatorScheduler.delayedBlock).isNotNull()
@@ -190,7 +190,7 @@
// PhysicsAnimatorTestUtils posts the cancellation to the main thread so we need to wait
// again
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
- assertThat(handleAnimator.isRunning()).isFalse()
+ handleAnimator.assertIsNotRunning()
}
@Test
@@ -219,7 +219,7 @@
// wait for the hide animation to start
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
- assertThat(handleAnimator.isRunning()).isTrue()
+ handleAnimator.assertIsRunning()
InstrumentationRegistry.getInstrumentation().runOnMainSync {
animator.onStashStateChangingWhileAnimating()
@@ -231,7 +231,7 @@
// PhysicsAnimatorTestUtils posts the cancellation to the main thread so we need to wait
// again
InstrumentationRegistry.getInstrumentation().waitForIdleSync()
- assertThat(handleAnimator.isRunning()).isFalse()
+ handleAnimator.assertIsNotRunning()
}
@Test
@@ -254,12 +254,12 @@
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
PhysicsAnimatorTestUtils.blockUntilFirstAnimationFrameWhereTrue(handleAnimator) { true }
- assertThat(handleAnimator.isRunning()).isTrue()
+ handleAnimator.assertIsRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isTrue()
assertThat(animatorScheduler.delayedBlock).isNotNull()
handleAnimator.cancel()
- assertThat(handleAnimator.isRunning()).isFalse()
+ handleAnimator.assertIsNotRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isFalse()
assertThat(animatorScheduler.delayedBlock).isNull()
}
@@ -287,7 +287,7 @@
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
- assertThat(barAnimator.isRunning()).isFalse()
+ barAnimator.assertIsNotRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isTrue()
assertThat(bubbleBarView.alpha).isEqualTo(1)
assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
@@ -329,7 +329,7 @@
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
- assertThat(barAnimator.isRunning()).isFalse()
+ barAnimator.assertIsNotRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isTrue()
assertThat(bubbleBarView.alpha).isEqualTo(1)
assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_TASKBAR)
@@ -363,7 +363,7 @@
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y)
- assertThat(barAnimator.isRunning()).isFalse()
+ barAnimator.assertIsNotRunning()
assertThat(bubbleBarView.isAnimatingNewBubble).isTrue()
assertThat(bubbleBarView.alpha).isEqualTo(1)
assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_HOTSEAT)
@@ -412,6 +412,18 @@
.thenReturn(BAR_TRANSLATION_Y_FOR_TASKBAR)
}
+ private fun <T> PhysicsAnimator<T>.assertIsRunning() {
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ assertThat(isRunning()).isTrue()
+ }
+ }
+
+ private fun <T> PhysicsAnimator<T>.assertIsNotRunning() {
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {
+ assertThat(isRunning()).isFalse()
+ }
+ }
+
private class TestBubbleBarViewAnimatorScheduler : BubbleBarViewAnimator.Scheduler {
var delayedBlock: Runnable? = null