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

Commit 2127943f authored by Omar Miatello's avatar Omar Miatello
Browse files

revert: Added doOnTearDown on MonotonicClockTestScope. 2/2

The new method was only used in one file, and after discussion with the
team, we decided to remove it and re-evaluate its use later, based on
the usage of the new pattern.

This CL revert ag/32700659

Test: Code reverted, old tests
Bug: 404975090
Flag: com.android.systemui.scene_container
Change-Id: I22cd1fe75efcc45fa35deb75df3ca58b4b744354
parent 07a66114
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