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

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

Fix awaitFrames waiting for one frame too few

Since onFrame is based on a MutableStateFlow, there is
always the current value delivered first.

This is intended for `awaitCondition`, since this should complete
immediately if the condition is already met. As a consequence,
awaitFrames needs to wait for `count + 1` frames

Flag: TEST_ONLY
Bug: 389637975
Test: existing unit tests
Change-Id: I491cdeeda0d6425c90318bbfa38484eec494f4ee
parent 8584977e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ class TransitionAnimatorTest(
            sampleIntervalMs = 16L
        } else {
            assertTrue { animation is TransitionAnimator.InterpolatedAnimation }
            motionControl = MotionControl { awaitFrames(count = 26) }
            motionControl = MotionControl { awaitFrames(count = 25) }
            sampleIntervalMs = 20L
        }

+11 −11
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ private class MotionControlImpl(
    }

    override suspend fun awaitFrames(count: Int) {
        onFrame.take(count).collect {}
        onFrame.take(count + 1).collect {}
    }

    private fun MotionControlFn.launch(): Job {
+2 −2
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ class AnimatorTestRuleToolkitTest {
        val recordedMotion =
            record(
                animatedBox,
                MotionControl { awaitFrames(count = 26) },
                MotionControl { awaitFrames(count = 25) },
                sampleIntervalMs = 20L,
                recordScreenshots = true,
            )
@@ -103,7 +103,7 @@ class AnimatorTestRuleToolkitTest {
        val recordedMotion =
            record(
                animatedBox,
                MotionControl { awaitFrames(count = 26) },
                MotionControl { awaitFrames(count = 25) },
                sampleIntervalMs = 20L,
                recordScreenshots = false,
            )