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

Commit d19e7b4c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "revert: Added doOnTearDown on MonotonicClockTestScope. 2/2" into main

parents 47fbea01 2127943f
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -37,13 +37,32 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.motion.compose.MonotonicClockTestScope
import platform.test.motion.compose.runMonotonicClockTest

/** Benchmark, which will execute on an Android device. Previous results: go/mm-microbenchmarks */
@RunWith(AndroidJUnit4::class)
class MotionValueBenchmark {
    @get:Rule val benchmarkRule = BenchmarkRule()

    private val tearDownOperations = mutableListOf<() -> Unit>()

    /**
     * Runs a test block within a [MonotonicClockTestScope] provided by the underlying
     * [platform.test.motion.compose.runMonotonicClockTest] and ensures automatic cleanup.
     *
     * This mechanism provides a convenient way to register cleanup actions (e.g., stopping
     * coroutines, resetting states) that should reliably run at the end of the test, simplifying
     * test setup and teardown.
     */
    private fun runMonotonicClockTest(block: suspend MonotonicClockTestScope.() -> Unit) {
        return platform.test.motion.compose.runMonotonicClockTest {
            try {
                block()
            } finally {
                tearDownOperations.fastForEach { it.invoke() }
            }
        }
    }

    private data class TestData(
        val motionValue: MotionValue,
        val gestureContext: DistanceGestureContext,
@@ -144,7 +163,7 @@ class MotionValueBenchmark {

    private fun MonotonicClockTestScope.keepRunningDuringTest(motionValue: MotionValue) {
        val keepRunningJob = launch { motionValue.keepRunning() }
        doOnTearDown { keepRunningJob.cancel() }
        tearDownOperations += { keepRunningJob.cancel() }
    }

    private val MotionSpec.Companion.ZeroToOne_AtOne
+1 −1
Original line number Diff line number Diff line
@@ -545,7 +545,6 @@ class MotionValueTest {
    fun keepRunning_concurrentInvocationThrows() = runMonotonicClockTest {
        val underTest = MotionValue({ 1f }, FakeGestureContext, label = "Foo")
        val realJob = launch { underTest.keepRunning() }
        doOnTearDown { realJob.cancel() }
        testScheduler.runCurrent()

        assertThat(realJob.isActive).isTrue()
@@ -557,6 +556,7 @@ class MotionValueTest {
            assertThat(e).hasMessageThat().contains("MotionValue(Foo) is already running")
        }
        assertThat(realJob.isActive).isTrue()
        realJob.cancel()
    }

    @Test