From 99441e2fcc7cb91643f65b6c6ceb1357019972bd Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Thu, 19 Dec 2019 03:21:52 +0800 Subject: [PATCH] Add test device for CI in release process (#417) --- .circleci/config.yml | 32 ++++++++++++++++ cloud_test.sh | 37 +++++++++++++++++-- .../CrashReportBuilderInstrumentedTest.java | 8 +++- .../AlarmMangerInstrumentationTest.java | 14 +++---- .../telemetry/AlarmSchedulerFlusher.java | 11 ++++-- 5 files changed, 85 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f47bcf010..8f2ef8e00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,6 +93,38 @@ jobs: IS_LOCAL_DEVELOPMENT: false steps: - checkout + - run: + name: Build testapp APK + command: | + ./gradlew accessToken + ./gradlew app:assembleDebug + - run: + name: Build release to test ProGuard rules + command: ./gradlew app:assembleRelease + - run: + name: Build all the test APK + command: ./gradlew assembleAndroidTest + - run: + name: Log in to Google Cloud Platform + shell: /bin/bash -euo pipefail + command: | + echo "${GCLOUD_SERVICE_ACCOUNT_JSON}" > secret.json + gcloud auth activate-service-account --key-file secret.json --project mapbox-events-android + rm secret.json + - run: + name: Run libcore instrumentation tests on Firebase with more devices + no_output_timeout: 20m + command: | + build_dir="libcore/build" + test_apk_path="outputs/apk/androidTest/debug/libcore-debug-androidTest.apk" + ./cloud_test.sh $build_dir $test_apk_path $CIRCLE_BUILD_NUM true + - run: + name: Run libtelemetry instrumentation tests on Firebase with more devices + no_output_timeout: 20m + command: | + build_dir="libtelemetry/build" + test_apk_path="outputs/apk/androidTest/full/debug/libtelemetry-full-debug-androidTest.apk" + ./cloud_test.sh $build_dir $test_apk_path $CIRCLE_BUILD_NUM true - run: name: Generate Maven credentials shell: /bin/bash -euo pipefail diff --git a/cloud_test.sh b/cloud_test.sh index 26bef6114..1ade40426 100755 --- a/cloud_test.sh +++ b/cloud_test.sh @@ -5,15 +5,44 @@ build_dir="$1" module=$(echo "$build_dir" | cut -d "/" -f1) test_apk_path="$2" results_dir="$3" +is_release="$4" + +devices="--device model=m0,version=18,locale=en,orientation=portrait \ +--device model=hammerhead,version=21,locale=en,orientation=portrait \ +--device model=hammerhead,version=23,locale=en,orientation=landscape \ +--device model=sailfish,version=26,locale=en,orientation=portrait \ +--device model=sailfish,version=28,locale=en,orientation=portrait \ +" +if [ "$is_release" == "true" ]; then +echo "Is release, adding more devices" +devices="$devices +--device model=g3,version=19,locale=en,orientation=portrait \ +--device model=Nexus6,version=21,locale=en,orientation=portrait \ +--device model=Nexus6,version=22,locale=en,orientation=portrait \ +--device model=Nexus6,version=23,locale=en,orientation=portrait \ +--device model=j1acevelte,version=22,locale=en,orientation=portrait \ +--device model=sailfish,version=25,locale=en,orientation=portrait \ +--device model=sailfish,version=27,locale=en,orientation=portrait \ +--device model=starqlteue,version=26,locale=en,orientation=portrait \ +--device model=taimen,version=26,locale=en,orientation=portrait \ +--device model=taimen,version=27,locale=en,orientation=portrait \ +--device model=walleye,version=26,locale=en,orientation=portrait \ +--device model=walleye,version=27,locale=en,orientation=portrait \ +--device model=walleye,version=28,locale=en,orientation=portrait \ +--device model=zeroflte,version=23,locale=en,orientation=portrait \ +--device model=hero2lte,version=23,locale=en,orientation=portrait \ +--device model=cheryl,version=25,locale=en,orientation=portrait \ +--device model=HWMHA,version=24,locale=en,orientation=portrait \ +--device model=FRT,version=27,locale=en,orientation=portrait \ +" +fi + gcloud firebase test android models list gcloud firebase test android run --type instrumentation \ --app app/build/outputs/apk/full/debug/app-full-debug.apk \ --test "${build_dir}/${test_apk_path}" \ --results-dir="$results_dir" \ - --device model=hammerhead,version=21,locale=en,orientation=portrait \ - --device model=hammerhead,version=23,locale=en,orientation=landscape \ - --device model=sailfish,version=26,locale=en,orientation=portrait \ - --device model=sailfish,version=28,locale=en,orientation=portrait \ + $(echo $devices) \ --environment-variables coverage=true,coverageFile="/sdcard/${module}_coverage.ec" \ --directories-to-pull /sdcard \ --timeout 20m diff --git a/libcore/src/androidTest/java/com/mapbox/android/core/crashreporter/CrashReportBuilderInstrumentedTest.java b/libcore/src/androidTest/java/com/mapbox/android/core/crashreporter/CrashReportBuilderInstrumentedTest.java index dc206d9e8..151d10701 100644 --- a/libcore/src/androidTest/java/com/mapbox/android/core/crashreporter/CrashReportBuilderInstrumentedTest.java +++ b/libcore/src/androidTest/java/com/mapbox/android/core/crashreporter/CrashReportBuilderInstrumentedTest.java @@ -2,6 +2,9 @@ import android.content.Context; import android.support.test.InstrumentationRegistry; + +import org.json.JSONException; +import org.json.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,9 +44,10 @@ public void invalidBodyfromJson() { } @Test - public void validBodyfromJson() { + public void validBodyfromJson() throws JSONException { CrashReport report = CrashReportBuilder.fromJson(validJson); - assertEquals(validJson.trim(), report.toJson()); + JSONObject jsonValidJson = new JSONObject(validJson); + assertEquals(jsonValidJson.toString(), report.toJson()); } @Test diff --git a/libtelemetry/src/androidTestFull/java/com/mapbox/android/telemetry/AlarmMangerInstrumentationTest.java b/libtelemetry/src/androidTestFull/java/com/mapbox/android/telemetry/AlarmMangerInstrumentationTest.java index 97eca56e2..945015b2f 100644 --- a/libtelemetry/src/androidTestFull/java/com/mapbox/android/telemetry/AlarmMangerInstrumentationTest.java +++ b/libtelemetry/src/androidTestFull/java/com/mapbox/android/telemetry/AlarmMangerInstrumentationTest.java @@ -27,7 +27,7 @@ public void checksAlarmCancelledProperly() throws InterruptedException { AlarmReceiver alarmReceiver = obtainAlarmReceiver(broadcastTrack, latch); AlarmSchedulerFlusher theAlarmSchedulerFlusher = new AlarmSchedulerFlusher(context, alarmManager, - alarmReceiver); + alarmReceiver); long elapsedMockedTime = 2000; long elapsedMockedTime2 = 5000; @@ -39,9 +39,8 @@ public void checksAlarmCancelledProperly() throws InterruptedException { theAlarmSchedulerFlusher.scheduleExact(elapsedMockedTime2); Assert.assertFalse(latch.await(30, TimeUnit.SECONDS)); - int result = broadcastTrack.get(); - Assert.assertEquals(1, result); + Assert.assertEquals(new Integer(1), broadcastTrack.get()); } @Test @@ -62,8 +61,7 @@ public void checksScheduleExact() throws Exception { AlarmManager mockedAlarmManager = mock(AlarmManager.class); AlarmReceiver mockedAlarmReceiver = mock(AlarmReceiver.class); AlarmSchedulerFlusher theAlarmSchedulerFlusher = new AlarmSchedulerFlusher(mockedContext, mockedAlarmManager, - mockedAlarmReceiver); - + mockedAlarmReceiver); Assert.assertTrue(theAlarmSchedulerFlusher.scheduleExact(25)); } @@ -71,10 +69,12 @@ private static AlarmReceiver obtainAlarmReceiver(final AtomicReference final CountDownLatch latch) { return new AlarmReceiver(new SchedulerCallback() { @Override - public void onPeriodRaised() {} + public void onPeriodRaised() { + } @Override - public void onError() {} + public void onError() { + } }) { @Override public void onReceive(Context context, Intent intent) { diff --git a/libtelemetry/src/full/java/com/mapbox/android/telemetry/AlarmSchedulerFlusher.java b/libtelemetry/src/full/java/com/mapbox/android/telemetry/AlarmSchedulerFlusher.java index 751fe5605..0d995b772 100644 --- a/libtelemetry/src/full/java/com/mapbox/android/telemetry/AlarmSchedulerFlusher.java +++ b/libtelemetry/src/full/java/com/mapbox/android/telemetry/AlarmSchedulerFlusher.java @@ -7,6 +7,7 @@ import android.content.IntentFilter; import android.os.Build; import android.os.SystemClock; +import android.support.annotation.RestrictTo; import android.support.annotation.VisibleForTesting; import static com.mapbox.android.telemetry.SchedulerFlusherFactory.SCHEDULER_FLUSHER_INTENT; @@ -41,14 +42,16 @@ public void schedule(long elapsedRealTime) { /* only exposed for testing not dealing directly with alarm logic */ @VisibleForTesting + @RestrictTo(RestrictTo.Scope.TESTS) boolean scheduleExact(long interval) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { manager.setExact(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + interval, - pendingIntent); - return true; + pendingIntent); + } else { + manager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + interval, + pendingIntent); } - - return false; + return true; } @Override