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

Commit 972517ab authored by Omar Miatello's avatar Omar Miatello
Browse files

MM tests should fail if they produce unexpected wtf logs

In eng-builds, some misconfiguration in a MotionValue would cause a
crash. However, in tests (and in production), we want animations to
proceed even with such errors.
When a test ends, we should check loggedFailures, if they were expected.

Test: atest MotionValueTest
Bug: 420622452
Flag: com.android.systemui.scene_container
Change-Id: I640c21fde03785bd33920bb8a13b3bb866191d25
parent 345dac54
Loading
Loading
Loading
Loading
+31 −10
Original line number Diff line number Diff line
@@ -14,8 +14,6 @@
 * limitations under the License.
 */

@file:OptIn(ExperimentalCoroutinesApi::class)

package com.android.mechanics

import android.util.Log
@@ -52,7 +50,6 @@ import com.android.mechanics.testing.input
import com.android.mechanics.testing.isStable
import com.android.mechanics.testing.output
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import org.junit.Rule
import org.junit.Test
@@ -201,6 +198,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
        ) {
            animateValueTo(21f, changePerFrame = 3f)
            awaitStable()

            // TODO(b/420622452) This test should not produce a WTF log.
            wtfLog.removeLoggedFailures()
        }

    @Test
@@ -214,6 +214,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
        ) {
            animateValueTo(30f, changePerFrame = 3f)
            awaitStable()

            // TODO(b/420622452) This test should not produce a WTF log.
            wtfLog.removeLoggedFailures()
        }

    @Test
@@ -245,6 +248,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
            awaitStable()
            animateValueTo(3f)
            awaitStable()

            // TODO(b/420622452) This test should not produce a WTF log.
            wtfLog.removeLoggedFailures()
        }

    @Test
@@ -519,7 +525,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
            animatedInputSequence(0f, 1f, 1f, 0f, 0f)
        }

        assertThat(wtfLog.loggedFailures).isEmpty()
        assertThat(wtfLog.hasLoggedFailures()).isFalse()
    }

    @Test
@@ -546,8 +552,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
            animatedInputSequence(0f, 0f)
        }

        assertThat(wtfLog.loggedFailures).hasSize(1)
        assertThat(wtfLog.loggedFailures.first()).startsWith("Delta between mappings is undefined")
        val loggedFailures = wtfLog.removeLoggedFailures()
        assertThat(loggedFailures).hasSize(1)
        assertThat(loggedFailures.first()).startsWith("Delta between mappings is undefined")
    }

    @Test
@@ -569,9 +576,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
        ) {
            animatedInputSequence(0f, 0.5f, 1f, 1.5f, 2f, 3f)
        }
        assertThat(wtfLog.loggedFailures).hasSize(1)
        assertThat(wtfLog.loggedFailures.first())
            .startsWith("Delta between breakpoints is undefined")
        val loggedFailures = wtfLog.removeLoggedFailures()
        assertThat(loggedFailures).hasSize(1)
        assertThat(loggedFailures.first()).startsWith("Delta between breakpoints is undefined")
    }

    @Test
@@ -610,7 +617,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
    }

    class WtfLogRule : ExternalResource() {
        val loggedFailures = mutableListOf<String>()
        private val loggedFailures = mutableListOf<String>()

        private lateinit var oldHandler: TerribleFailureHandler

@@ -625,6 +632,20 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def

        override fun after() {
            Log.setWtfHandler(oldHandler)

            // In eng-builds, some misconfiguration in a MotionValue would cause a crash. However,
            // in tests (and in production), we want animations to proceed even with such errors.
            // When a test ends, we should check loggedFailures, if they were expected.
            assertThat(loggedFailures).isEmpty()
        }

        fun hasLoggedFailures() = loggedFailures.isNotEmpty()

        fun removeLoggedFailures(): List<String> {
            if (loggedFailures.isEmpty()) error("loggedFailures is empty")
            val list = loggedFailures.toList()
            loggedFailures.clear()
            return list
        }
    }