Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test device for CI in release process #417

Merged
merged 11 commits into from
Dec 18, 2019
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
harvsu marked this conversation as resolved.
Show resolved Hide resolved
- 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
Expand Down
37 changes: 33 additions & 4 deletions cloud_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
harvsu marked this conversation as resolved.
Show resolved Hide resolved
--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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -62,19 +61,20 @@ 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));
}

private static AlarmReceiver obtainAlarmReceiver(final AtomicReference<Integer> broadcastTrack,
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down