Skip to content

Commit e4bbce4

Browse files
committed
fix(perf): handle auth state across iterations, source .env for seed
- Detect scanner_view on launch to handle already-authenticated iterations (BaselineProfileRule preserves app data between collection passes) - Source .env/.env.local for SEED_PHRASE so seed is not passed on CLI - CLI args still override .env value
1 parent a2f7122 commit e4bbce4

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

apps/flipcash/benchmark/src/main/kotlin/com/flipcash/benchmark/BaselineProfileGenerator.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,32 @@ class BaselineProfileGenerator {
3535
rule.collect(
3636
packageName = PACKAGE_NAME,
3737
) {
38-
// 1. Cold start — app init, Hilt DI, Compose runtime bootstrap
38+
// Cold start — app init, Hilt DI, Compose runtime bootstrap
3939
pressHome()
4040
startActivityAndWait()
4141
device.waitForIdle()
4242

43-
val seed = seedPhrase
44-
if (seed.isNullOrBlank()) {
45-
// Pre-auth only: exercise login screen navigation
46-
preAuthJourney()
47-
} else {
48-
// Full journey: login then exercise main app screens
49-
login(seed)
43+
// After login, app data persists across iterations so subsequent
44+
// iterations launch directly into the scanner (already authenticated).
45+
val onScanner = device.hasObject(By.res("scanner_view"))
46+
47+
if (onScanner) {
48+
// Already logged in from a prior iteration
5049
scannerJourney()
5150
walletJourney()
5251
giveJourney()
5352
menuJourney()
53+
} else {
54+
val seed = seedPhrase
55+
if (seed.isNullOrBlank()) {
56+
preAuthJourney()
57+
} else {
58+
login(seed)
59+
scannerJourney()
60+
walletJourney()
61+
giveJourney()
62+
menuJourney()
63+
}
5464
}
5565
}
5666
}

scripts/benchmark.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ usage() {
66
echo ""
77
echo " -t CLASS Run a specific test class (e.g. StartupBenchmark, BaselineProfileGenerator)"
88
echo " -d SERIAL Target a specific device (adb serial or emulator name)"
9-
echo " seed ... Seed phrase for authenticated user journeys"
9+
echo " seed ... Seed phrase for authenticated user journeys (overrides .env)"
10+
echo ""
11+
echo " SEED_PHRASE can also be set in .env or .env.local"
1012
echo ""
1113
echo "Examples:"
12-
echo " scripts/benchmark.sh # all benchmarks, no auth"
13-
echo " scripts/benchmark.sh word1 word2 word3 ... # all benchmarks, with auth"
14+
echo " scripts/benchmark.sh # all benchmarks, seed from .env"
1415
echo " scripts/benchmark.sh -t StartupBenchmark # startup only, no auth"
15-
echo " scripts/benchmark.sh -d emulator-5554 -t BaselineProfileGenerator word1 word2 ..."
16+
echo " scripts/benchmark.sh -d emulator-5554 -t BaselineProfileGenerator"
1617
exit 1
1718
}
1819

20+
# Source .env files for SEED_PHRASE and other config
21+
for envfile in .env .env.local; do
22+
[[ -f "$envfile" ]] && set -a && source "$envfile" && set +a
23+
done
24+
1925
TEST_CLASS=""
2026
DEVICE_SERIAL=""
2127

@@ -29,7 +35,10 @@ while getopts "t:d:h" opt; do
2935
done
3036
shift $((OPTIND - 1))
3137

32-
SEED_PHRASE="$*"
38+
# CLI args override .env
39+
if [[ $# -gt 0 ]]; then
40+
SEED_PHRASE="$*"
41+
fi
3342

3443
GRADLE_ARGS=(
3544
:apps:flipcash:benchmark:connectedBenchmarkAndroidTest
@@ -41,7 +50,7 @@ if [[ -n "$TEST_CLASS" ]]; then
4150
GRADLE_ARGS+=("-Pandroid.testInstrumentationRunnerArguments.class=com.flipcash.benchmark.$TEST_CLASS")
4251
fi
4352

44-
if [[ -n "$SEED_PHRASE" ]]; then
53+
if [[ -n "${SEED_PHRASE:-}" ]]; then
4554
GRADLE_ARGS+=("-Pandroid.testInstrumentationRunnerArguments.SEED_PHRASE=$SEED_PHRASE")
4655
fi
4756

0 commit comments

Comments
 (0)