Skip to content

Commit

Permalink
[reaper] Add stress sample (#256)
Browse files Browse the repository at this point in the history
* [reaper] Add stress sample

* Detekt fixes, wireup stress sample to match existing sample, leverage stress sample for device spread tests

* Fix apk names

* Add debug

* [reaper] Add stress sample

* Fixes/rollback to sample UI

* Fix path

* Leverage debug

* Fix

* Fix reaper

* Run on release variant

* Fix to run against release

* default runner

* Fix attempt

* Different runner

* Back to debug

* Fix UI test

---------

Co-authored-by: Ryan Brooks <[email protected]>
  • Loading branch information
chromy and rbro112 authored Sep 19, 2024
1 parent 929b9f2 commit 3501dd4
Show file tree
Hide file tree
Showing 24 changed files with 320,662 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/reaper-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
java-version: '17'
distribution: 'adopt'
- name: Generate target APK
run: ./gradlew :reaper:sample:app:assembleDebug -Pandroid.useAndroidX=true
run: ./gradlew :reaper:sample:stress:assembleDebug -Pandroid.useAndroidX=true
env:
EMERGE_REAPER_API_KEY: ${{ secrets.EMERGE_REAPER_API_KEY }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
- name: Generate test APK
run: ./gradlew :reaper:sample:app:assembleAndroidTest -Pandroid.useAndroidX=true
run: ./gradlew :reaper:sample:stress:assembleAndroidTest -Pandroid.useAndroidX=true
env:
EMERGE_REAPER_API_KEY: ${{ secrets.EMERGE_REAPER_API_KEY }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
Expand All @@ -60,8 +60,8 @@ jobs:
run: |
gcloud firebase test android run \
--type instrumentation \
--app reaper/sample/app/build/outputs/apk/debug/app-debug.apk \
--test reaper/sample/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
--app reaper/sample/stress/build/outputs/apk/debug/stress-debug.apk \
--test reaper/sample/stress/build/outputs/apk/androidTest/debug/stress-debug-androidTest.apk \
--device model=redfin,version=30,locale=en,orientation=portrait \
--device model=b0q,version=33,locale=en,orientation=portrait \
--device model=Nexus6P,version=26,locale=en,orientation=portrait \
Expand Down
1 change: 1 addition & 0 deletions reaper/sample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ dependencies {
androidTestImplementation(libs.compose.runtime)
androidTestImplementation(libs.compose.ui)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.uiautomator)
Expand Down
1 change: 0 additions & 1 deletion reaper/sample/manuallyInitializedApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ android {
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
Expand Down
110 changes: 110 additions & 0 deletions reaper/sample/stress/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.buildconfig)
id("com.emergetools.android")
}

emerge {
apiToken.set(System.getenv("EMERGE_API_TOKEN"))

vcs {
gitHub {
repoName.set("emerge-android")
repoOwner.set("EmergeTools")
}
}

reaper {
enabledVariants.set(listOf("releaseWithReaper", "debug"))
publishableApiKey.set(System.getenv("EMERGE_REAPER_API_KEY") ?: "<key>")
}
}

android {
namespace = "com.emergetools.reaper.sample.stress"
compileSdk = 34

defaultConfig {
applicationId = "com.emergetools.reaper.sample.stress"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
getByName("debug") {
applicationIdSuffix = ".debug"
isDebuggable = true
}
getByName("release") {
isMinifyEnabled = true
}
create("releaseWithReaper") {
initWith(getByName("release"))
// Don't minify androidTest application
if (project.hasProperty("isAndroidTest")) {
isMinifyEnabled = false
} else {
isMinifyEnabled = true
}

matchingFallbacks += listOf("release")
signingConfig = signingConfigs.getByName("debug")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.extension.get()
}
}

buildConfig {
className("ReaperConfig")
packageName("com.emergetools.reaper.sample.stress")
}

dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.kotlinx.serialization)

// Reaper SDK
implementation(projects.reaper.reaper)

implementation(platform(libs.compose.bom))
implementation(libs.compose.ui)
implementation(libs.compose.ui.tooling)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.material)
implementation(libs.androidx.test.core.ktx)

androidTestImplementation(libs.compose.runtime)
androidTestImplementation(libs.compose.ui)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.uiautomator)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.emergetools.reaper.sample.stress

import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ReaperStressSampleUiTest {
@Test
fun navigateToDetailScreen() {
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

device.pressHome()

val launcherPackage: String = device.launcherPackageName
assertNotNull(launcherPackage)
device.wait(
Until.hasObject(By.pkg(launcherPackage).depth(0)),
5000,
)

val context = ApplicationProvider.getApplicationContext<Context>()

val intent = context.packageManager.getLaunchIntentForPackage(
context.packageName
)?.apply {
// Clear out any previous instances
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
context.startActivity(intent)

// Wait for the app to appear
device.wait(
Until.hasObject(By.pkg(context.packageName).depth(0)),
10000
)

// Click on the first item in the list
device.findObject(By.text("Story 1")).click()

// Give time to land on next screen
Thread.sleep(1000)

// Background app for reaper report to post
device.pressHome()

// Give reaper report time to post
Thread.sleep(5000)
}
}
19 changes: 19 additions & 0 deletions reaper/sample/stress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="0.0.1">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application>
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.emergetools.reaper.sample.stress

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.emergetools.reaper.sample.stress.numbers.Number0
import com.emergetools.reaper.sample.stress.numbers.Number19
import com.emergetools.reaper.sample.stress.numbers.Number9999
import com.emergetools.reaper.sample.stress.screen.Story
import com.emergetools.reaper.sample.stress.screen.StoryDetailScreen
import com.emergetools.reaper.sample.stress.screen.StoryList
import com.emergetools.reaper.sample.stress.screen.StoryListScreen

class MainActivity : ComponentActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val a = Number19()
val b = Number9999()
val title = "fib(${a.value()}) = ${a.fib()}, sumTo(0, ${b.value()}) = ${Number0().sumTo(b)}"

setContent {
val navController = rememberNavController()

NavHost(
navController = navController,
startDestination = StoryList,
) {
composable<StoryList> {
StoryListScreen(
title = title,
navController = navController,
)
}
composable<Story> { backStackEntry ->
val story: Story = backStackEntry.toRoute()
StoryDetailScreen(
story = story,
navController = navController,
)
}
}
}
}
}
Loading

0 comments on commit 3501dd4

Please sign in to comment.