Reusable ADB script to populate the app with varied test data across 9 app sources (WhatsApp, Gmail, Telegram, Instagram, Slack, Messages, X, Calendar, System) spanning multiple days for UI/UX stress testing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
95 lines
2.6 KiB
Bash
Executable file
95 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# inject_test_data.sh — Injects test notifications from test_data.json into the SNI app
|
|
# Usage: ./scripts/inject_test_data.sh [--clear]
|
|
# --clear Clears the database before injecting
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
DATA_FILE="$SCRIPT_DIR/test_data.json"
|
|
PKG="com.roundingmobile.sni.dev"
|
|
RECEIVER="$PKG/com.roundingmobile.sni.instrumentation.TestBroadcastReceiver"
|
|
BATCH_SIZE=8
|
|
|
|
if [ ! -f "$DATA_FILE" ]; then
|
|
echo "ERROR: $DATA_FILE not found"
|
|
exit 1
|
|
fi
|
|
|
|
if ! adb devices | grep -q "device$"; then
|
|
echo "ERROR: No ADB device connected"
|
|
exit 1
|
|
fi
|
|
|
|
# Check app is running
|
|
if ! adb shell pidof "$PKG" > /dev/null 2>&1; then
|
|
echo "App not running. Launching..."
|
|
adb shell am start -n "$PKG/com.roundingmobile.sni.presentation.MainActivity"
|
|
sleep 2
|
|
fi
|
|
|
|
# Optional: clear DB first
|
|
if [ "${1:-}" = "--clear" ]; then
|
|
echo "Clearing database..."
|
|
adb shell am broadcast -a com.roundingmobile.sni.test.CLEAR_DB -n "$RECEIVER" > /dev/null
|
|
sleep 1
|
|
fi
|
|
|
|
NOW_MS=$(date +%s%3N)
|
|
|
|
# Use python3 to convert age_minutes to timestamps, strip that field,
|
|
# and split into batches of BATCH_SIZE
|
|
TOTAL=$(python3 -c "
|
|
import json, sys
|
|
|
|
with open('$DATA_FILE') as f:
|
|
data = json.load(f)
|
|
|
|
now = $NOW_MS
|
|
for item in data:
|
|
age = item.pop('age_minutes', 0)
|
|
item['timestamp'] = now - (age * 60000)
|
|
|
|
# Split into batches
|
|
batch_size = $BATCH_SIZE
|
|
batches = [data[i:i+batch_size] for i in range(0, len(data), batch_size)]
|
|
|
|
for i, batch in enumerate(batches):
|
|
# Write each batch to a temp file
|
|
with open(f'/tmp/sni_batch_{i}.json', 'w') as f:
|
|
json.dump(batch, f, separators=(',', ':'))
|
|
|
|
print(f'{len(data)} {len(batches)}')
|
|
")
|
|
|
|
NOTIF_COUNT=$(echo "$TOTAL" | cut -d' ' -f1)
|
|
BATCH_COUNT=$(echo "$TOTAL" | cut -d' ' -f2)
|
|
|
|
echo "Injecting $NOTIF_COUNT notifications in $BATCH_COUNT batches..."
|
|
|
|
INJECTED=0
|
|
for i in $(seq 0 $((BATCH_COUNT - 1))); do
|
|
BATCH_FILE="/tmp/sni_batch_${i}.json"
|
|
BATCH_JSON=$(cat "$BATCH_FILE")
|
|
|
|
adb shell am broadcast \
|
|
-a com.roundingmobile.sni.test.INJECT_BATCH \
|
|
-n "$RECEIVER" \
|
|
--es json "'$BATCH_JSON'" > /dev/null 2>&1
|
|
|
|
BATCH_ITEMS=$(python3 -c "import json; print(len(json.load(open('$BATCH_FILE'))))")
|
|
INJECTED=$((INJECTED + BATCH_ITEMS))
|
|
echo " Batch $((i+1))/$BATCH_COUNT done ($INJECTED/$NOTIF_COUNT)"
|
|
sleep 0.5
|
|
done
|
|
|
|
# Clean up temp files
|
|
rm -f /tmp/sni_batch_*.json
|
|
|
|
# Verify
|
|
sleep 1
|
|
adb shell am broadcast -a com.roundingmobile.sni.test.DUMP_STATE -n "$RECEIVER" > /dev/null
|
|
sleep 1
|
|
COUNT=$(adb logcat -d -s CLAUDE_TEST:V | grep "STATE db_count=" | tail -1 | sed 's/.*db_count=//')
|
|
echo ""
|
|
echo "Done! Database count: $COUNT"
|