Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d31abf2 authored by Robin Lee's avatar Robin Lee
Browse files

Deflake testCancel_sneakyCancelBeforeUpdate

Waiting one frame for the animation to start is a safe bet. Waiting an
additional frame for the cancellation to take effect isn't.

This test was 50% flaky before.

Test: atest --iterations 10 'com.android.server.wm.SurfaceAnimationRunnerTest#testCancel_sneakyCancelBeforeUpdate'
Bug: 71719744
Change-Id: I97ab43e0a31107bd0497a8e02be88cf331d71ce1
parent c34e5869
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ public class SurfaceAnimationRunnerTest {
    @FlakyTest(bugId = 71719744)
    @Test
    public void testCancel_sneakyCancelBeforeUpdate() throws Exception {
        final CountDownLatch animationCancelled = new CountDownLatch(1);

        mSurfaceAnimationRunner = new SurfaceAnimationRunner(null, () -> new ValueAnimator() {
            {
                setFloatValues(0f, 1f);
@@ -162,6 +164,7 @@ public class SurfaceAnimationRunnerTest {
                    // interleaving of multiple threads. Muahahaha
                    if (animation.getCurrentPlayTime() > 0) {
                        mSurfaceAnimationRunner.onAnimationCancelled(mMockSurface);
                        animationCancelled.countDown();
                    }
                    listener.onAnimationUpdate(animation);
                });
@@ -170,11 +173,7 @@ public class SurfaceAnimationRunnerTest {
        when(mMockAnimationSpec.getDuration()).thenReturn(200L);
        mSurfaceAnimationRunner.startAnimation(mMockAnimationSpec, mMockSurface, mMockTransaction,
                this::finishedCallback);

        // We need to wait for two frames: The first frame starts the animation, the second frame
        // actually cancels the animation.
        waitUntilNextFrame();
        waitUntilNextFrame();
        assertTrue(animationCancelled.await(1, SECONDS));
        assertTrue(mSurfaceAnimationRunner.mRunningAnimations.isEmpty());
        verify(mMockAnimationSpec, atLeastOnce()).apply(any(), any(), eq(0L));
    }