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

Commit f06ee379 authored by Mike Schneider's avatar Mike Schneider
Browse files

Fix flakiness in MotionValue test

The `framesCount` was  not reproducibly incremented on every frame;
probably due to how the coroutines are scheduled during awaitIdle(). In
debug logging I saw some fluctuation in framesCount. However,
the time passed is 100% reproducible, so using this for the assertion
instead.

Test: atest MotionValueTest --rerun-until-failure 100
Flag: TEST_ONLY
Bug: 387996051
Change-Id: Id389f534c2303a0381911e31890596e7d0b841ac
parent b6eab990
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -434,6 +434,8 @@ class MotionValueTest {
            assertThat(framesCount).isEqualTo(it + 1)
        }

        val timeBeforeAutoAdvance = rule.mainClock.currentTime

        // But this will stop as soon as the animation is finished. Skip forward.
        rule.mainClock.autoAdvance = true
        rule.awaitIdle()
@@ -442,9 +444,13 @@ class MotionValueTest {
        assertThat(inspector.frame.isStable).isTrue()
        // ... and animations are suspended again.
        assertThat(inspector.isAnimating).isFalse()
        // Without too many assumptions about how long it took to settle the spring, should be
        // more than  160ms
        assertThat(framesCount).isGreaterThan(10)

        rule.awaitIdle()

        // Stabilizing the spring during awaitIdle() took 176ms (obtained from looking at reference
        // test runs). That time is expected to be 100% reproducible, given the starting
        // state/configuration of the spring before awaitIdle().
        assertThat(rule.mainClock.currentTime).isEqualTo(timeBeforeAutoAdvance + 176)
    }

    @Test