From c9ec4d1cbbfa940522896bd76901518cd79dc9e3 Mon Sep 17 00:00:00 2001 From: Mahmudul Hasan Shohag Date: Thu, 16 Jan 2025 07:06:38 +0600 Subject: [PATCH] feat(benchmarks): add scan to gradle commands, update running car animation, and add extra log text to `UiDevice.waitAndFindObject` --- .github/workflows/build-beta-upload-android.yml | 2 ++ .../workflows/build-production-upload-android.yml | 2 ++ .../screens/animation/runningcar/RunningCarScreen.kt | 12 ++++++++++-- benchmarks/build.gradle.kts | 2 ++ .../whynotcompose/benchmarks/Utils.kt | 5 +++-- .../CompositionsModuleBaselineProfile.kt | 2 +- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-beta-upload-android.yml b/.github/workflows/build-beta-upload-android.yml index 48e85cd..93644b8 100644 --- a/.github/workflows/build-beta-upload-android.yml +++ b/.github/workflows/build-beta-upload-android.yml @@ -64,6 +64,7 @@ jobs: --info -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" + --scan - name: Generate baseline profile run: ./gradlew :app:generateBaselineProfile @@ -72,6 +73,7 @@ jobs: -Pandroid.experimental.androidTest.numManagedDeviceShards=1 -Pandroid.experimental.testOptions.managedDevices.maxConcurrentDevices=1 --stacktrace + --scan - name: Build & deploy Android release run: bundle exec fastlane android beta diff --git a/.github/workflows/build-production-upload-android.yml b/.github/workflows/build-production-upload-android.yml index 8671918..4b5414c 100644 --- a/.github/workflows/build-production-upload-android.yml +++ b/.github/workflows/build-production-upload-android.yml @@ -61,6 +61,7 @@ jobs: --info -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" + --scan - name: Generate baseline profile run: ./gradlew :app:generateBaselineProfile @@ -69,6 +70,7 @@ jobs: -Pandroid.experimental.androidTest.numManagedDeviceShards=1 -Pandroid.experimental.testOptions.managedDevices.maxConcurrentDevices=1 --stacktrace + --scan - name: Build & deploy Android release run: bundle exec fastlane android deploy diff --git a/app/src/main/kotlin/org/imaginativeworld/whynotcompose/ui/screens/animation/runningcar/RunningCarScreen.kt b/app/src/main/kotlin/org/imaginativeworld/whynotcompose/ui/screens/animation/runningcar/RunningCarScreen.kt index d829401..2db8710 100644 --- a/app/src/main/kotlin/org/imaginativeworld/whynotcompose/ui/screens/animation/runningcar/RunningCarScreen.kt +++ b/app/src/main/kotlin/org/imaginativeworld/whynotcompose/ui/screens/animation/runningcar/RunningCarScreen.kt @@ -52,6 +52,9 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -77,13 +80,18 @@ enum class CarState { @Composable fun RunningCarScreen() { - val animState = MutableStateFlow(CarState.INITIAL) + val animState = remember { MutableStateFlow(CarState.INITIAL) } + var isFirstTime by remember { mutableStateOf(true) } LaunchedEffect(Unit) { while (true) { animState.value = CarState.INITIAL - delay(3000) + if (isFirstTime) { + isFirstTime = false + } else { + delay(3000) + } animState.value = CarState.RUNNING diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 582cec7..776e93f 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -1,3 +1,5 @@ +@file:Suppress("UnstableApiUsage") + import com.android.build.api.dsl.ManagedVirtualDevice plugins { diff --git a/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/Utils.kt b/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/Utils.kt index 50f4df7..6576acc 100644 --- a/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/Utils.kt +++ b/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/Utils.kt @@ -46,9 +46,10 @@ fun UiDevice.flingElementDownUp(element: UiObject2) { * Waits until an object with [selector] if visible on screen and returns the object. * If the element is not available in [timeout], throws [AssertionError] */ -fun UiDevice.waitAndFindObject(selector: BySelector, timeout: Long, extraLogText: String = "No"): UiObject2 { +fun UiDevice.waitAndFindObject(selector: BySelector, timeout: Long, extraLogText: String = ""): UiObject2 { if (!wait(Until.hasObject(selector), timeout)) { - throw AssertionError("Element not found on screen in ${timeout}ms (selector=$selector) | $extraLogText") + val finalExtraLogText = if (extraLogText.isEmpty()) "" else " | $extraLogText" + throw AssertionError("Element not found on screen in ${timeout}ms (selector=$selector)$finalExtraLogText") } return findObject(selector) diff --git a/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/baselineprofile/CompositionsModuleBaselineProfile.kt b/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/baselineprofile/CompositionsModuleBaselineProfile.kt index b03333c..5526934 100644 --- a/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/baselineprofile/CompositionsModuleBaselineProfile.kt +++ b/benchmarks/src/main/kotlin/org/imaginativeworld/whynotcompose/benchmarks/baselineprofile/CompositionsModuleBaselineProfile.kt @@ -95,7 +95,7 @@ class CompositionsModuleBaselineProfile { // https://d.android.com/training/testing/other-components/ui-automator // Wait for home screen - device.waitAndFindObject(By.res("screen:home"), 5_000) + device.waitAndFindObject(By.res("screen:home"), 5_000, "Initial home screen") indexScreenTraverseActions( moduleButtonText = "Compositions",