From 2ceb63a94dd93312c81dd92bb935d0544b0cb941 Mon Sep 17 00:00:00 2001 From: Liran Binyamin Date: Wed, 20 Nov 2024 15:47:30 -0500 Subject: [PATCH] Deflake BubbleBarViewAnimatorTest Add a semaphore to block the test until the bubble bar is expanded. 100x run: http://ab/I94900010337166460 Flag: com.android.wm.shell.enable_bubble_bar Fixes: 380023942 Test: ab link above Change-Id: I473208255ef658ee532f54c2665889ee5c24e39e --- .../bubbles/animation/BubbleBarViewAnimator.kt | 2 +- .../animation/BubbleBarViewAnimatorTest.kt | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt index 6c354f3c0c..9b2f3a3224 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimator.kt @@ -473,8 +473,8 @@ constructor( ObjectAnimator.ofFloat(bubbleBarView, View.TRANSLATION_Y, ty - bubbleBarBounceDistanceInPx) .withDuration(BUBBLE_BAR_BOUNCE_ANIMATION_DURATION_MS) .withEndAction { - if (animatingBubble?.expand == true) expandBubbleBar() springBackAnimation.start() + if (animatingBubble?.expand == true) expandBubbleBar() } .start() } 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 582ea54bf0..0dfed4a8ee 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 @@ -48,6 +48,8 @@ import com.android.wm.shell.shared.animation.PhysicsAnimator import com.android.wm.shell.shared.animation.PhysicsAnimatorTestUtils import com.android.wm.shell.shared.bubbles.BubbleInfo import com.google.common.truth.Truth.assertThat +import java.util.concurrent.Semaphore +import java.util.concurrent.TimeUnit import org.junit.Before import org.junit.Rule import org.junit.Test @@ -764,10 +766,12 @@ class BubbleBarViewAnimatorTest { whenever(bubbleStashController.bubbleBarTranslationY) .thenReturn(BAR_TRANSLATION_Y_FOR_HOTSEAT) - val barAnimator = PhysicsAnimator.getInstance(bubbleBarView) - + val semaphore = Semaphore(0) var notifiedExpanded = false - val onExpanded = Runnable { notifiedExpanded = true } + val onExpanded = Runnable { + notifiedExpanded = true + semaphore.release() + } val animator = BubbleBarViewAnimator( bubbleBarView, @@ -792,7 +796,12 @@ class BubbleBarViewAnimatorTest { // the lift animation is complete; the spring back animation should start now InstrumentationRegistry.getInstrumentation().runOnMainSync {} - barAnimator.assertIsRunning() + + InstrumentationRegistry.getInstrumentation().waitForIdleSync() + + assertThat(semaphore.tryAcquire(5, TimeUnit.SECONDS)).isTrue() + // we should be expanded now + assertThat(bubbleBarView.isExpanded).isTrue() PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Y) // verify there is no hide animation @@ -800,7 +809,6 @@ class BubbleBarViewAnimatorTest { assertThat(animator.isAnimating).isFalse() assertThat(bubbleBarView.translationY).isEqualTo(BAR_TRANSLATION_Y_FOR_HOTSEAT) - assertThat(bubbleBarView.isExpanded).isTrue() verify(bubbleStashController).showBubbleBarImmediate() assertThat(notifiedExpanded).isTrue() }