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

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

Merge "MM tests should fail if they produce unexpected wtf logs" into main

parents 46bf7490 972517ab
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
        }
    }