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

Fix #1832 and part of #1831: Add example Espresso emulator test to GitHub CI #1844

Closed

Conversation

BenHenning
Copy link
Member

@BenHenning BenHenning commented Sep 16, 2020

Fix #1832
Fix part of #1831 (since only one test is being added).

Per https://github.com/marketplace/actions/android-emulator-runner it seems Android emulator tests are supported in GitHub actions, but only when run in Mac OS (due to Linux requiring KVM, and KVM not being broadly available in the machines running GitHub actions). Note that this PR introduces custom emulator management rather than using an existing action since this lets us better parallelize tasks, and lets us have predefined device profiles to run on.

This PR introduces a setup only for SplashActivityTest since we should be adding tests one at a time until we can guarantee broad stability. SplashActivityTest seems pretty reliable, so we can start with this one. That being said, this was tested with multiple test suites (see sample runs below). Features of the new job includes:

  1. Custom device profiles for various cases that we're interested in (with ease to add more)
  2. Support for running multiple test suites sequentially
  3. Support for creating AVDs & running Espresso tests locally using new scripts
  4. Faster runtimes by parallelizing emulator setup & the project Gradle build
  5. Logcat retention & upload after the tests run (per-test)
  6. Screen recordings of the test for both passes & failures
  7. Easy configuration of properties using GitHub Actions environment variables & matrix parameters

Note that the screen recording functionality was a bit tricky to implement. It currently works by sequentially logging up to 10 back-to-back videos using adb shell screenrecord (which can only record at most 3 minutes), then pieces them together in one video. I spent some time trying to get this to work using an in-app test fixture, but doing so requires a rooted device & further effort. For an idea on what that work looked like, see: 5368910.

Some other miscellaneous things to note:

  1. I don't think this should be a blocking check initially since it's a bit slow (even with optimization, SplashActivityTest alone takes 15 minutes to run + setup). We'll need to decide how to proceed, but I suggest keeping this as an optional run & possibly expand the test suite to the full suite for develop (that way we can at least revert PRs if they break something on Espresso after getting merged in).
  2. SDK 28 is being used instead of SDK 29 since SDK 29's emulator seems to have some occasional native crashes that are triggered from EGL calls during rendering.

ReactiveCircus/android-emulator-runner#90 is tracking how to use an environmental variable for defining the test suite instead of needing to specify it in-line. I decided to custom manage the emulator & AVD setup, instead, since it provides more flexibility.

Sample runs:

Per  https://github.com/marketplace/actions/android-emulator-runner it seems Android emulator tests are supported in GitHub actions, but only when run in Mac OS (due to Linux requiring KVM, and KVM not being broadly available in the machines running GitHub actions).

This PR introduces a setup only for SplashActivityTest since we should be adding tests one at a time until we can guarantee broad stability. SplashActivityTest seems pretty reliable, so we can start with this one.
Switch Pixel XL with Nexus 6 and run all tests instead of a specific one to try and debug why they're failing.
@BenHenning BenHenning marked this pull request as draft September 16, 2020 01:38
BenHenning and others added 12 commits September 15, 2020 18:41
Android SDK needs to be set up in the path correctly to build instrumented tests.
Temporarily remove other workflows, and add additional logging options for Gradle.
Add additional logs to investigate the build failure (possibly related to actions/runner-images#60 and DroidKaigi/conference-app-2020#710).
Introduce script to simplify the workflow setup & avoid pitfalls from quote escaping.
…f github.com:oppia/oppia-android into add-splash-activity-test-as-first-emulator-ci-action
Try different action for setting up Android SDK and add additional debug steps.
Add missing command to set up platform tools to make ADB available.
Use Java 8 since it may be required for the Android SDK manager (and for emulator tests--we don't actually use Java 9 for these).
Remove original setup-android action.
BenHenning added a commit to BenHenning/action-android that referenced this pull request Sep 16, 2020
Clarify the purpose of each step, and add a missing step that's needed for ADB to work correctly (``sdkmanager platform-tools``) per https://github.com/Malinskiy/action-android/blob/5c20fa7/.github/workflows/test-macos.yml#L16 and Malinskiy#22 (comment).

I noticed this when trying to get oppia/oppia-android#1844 to work.
BenHenning and others added 13 commits September 16, 2020 13:39
Limit Mac OS version to 10.15 since that's the version we're starting with, and try to run the emulator script directly to see if the environment variables are being set correctly.
Remove sudo to see if it's causing the environment variables to reset.
support for video recordings of running tests. This needs to be cleaned
up in a subsequent commit.

Note that this script makes use of an ./emulator_tests working directory
that was also added to .gitignore.
…f github.com:oppia/oppia-android into add-splash-activity-test-as-first-emulator-ci-action
The initial whitelist is just SplashActivityTest.
Fix environment variable export in a way that's compatible with sh.
unnecessary ADB step. Update run_emulator_tests to fail overall if any
tests fail. Temporarily run only one test in the only active test suite
(SplashActivityTest) to speed up the CI run for debugging.
Debug whether GitHub is defining an array env variable correctly.
Add parsing code for AVD device settings.
Use correct delimiter for device settings lists.
Fix syntax error. Remove parentheses from device parameters since it's only parsing based on spaces.
Add debugging for dev settings vars.
Fix device settings array variable reference.
@BenHenning BenHenning changed the title Fix ##1832 and part of #1831: Add example Espresso emulator test to GitHub CI Fix #1832 and part of #1831: Add example Espresso emulator test to GitHub CI Sep 22, 2020
BenHenning and others added 16 commits September 21, 2020 21:50
Also, some clean up & small fixes. Added more useful list of devices
that we can test on.
…f github.com:oppia/oppia-android into add-splash-activity-test-as-first-emulator-ci-action

+ post-merge fixes.

Conflicts:
	.github/workflows/main.yml
Specifically: remove debug lines, remove StateFragmentTest, start Gradle
build in parallel, and add proper support for multiple devices by segmenting
test output to its own directory.
And other miscellaneous documentation improvements.
SDK 29 has some occasional mul-overflow errors, so switching to SDK 28
for now for hopefully better stability.
Also, add timeout so that wait_for_emulator doesn't hang.
Install coreutils instead of timeout (for timeout functionality).
Re-add platforms SDK install.
Quiet sdkmanager output. Try again to use SDK 29 since 28 seems to unexpectedly have pathing issues.
Redirect stdout to /dev/null for sdkmanager since it probably works a bit better than using grep.
Attempt to run SplashActivityTest on all support devices at once.
Log build output in case something fails & upload it.
Fix upload artifacts naming & pathing, and turn off fail-fast for matrix expansions of jobs.
Set access token for cancellation action.
Only block on the Gradle build if it isn't already running.
Malinskiy pushed a commit to Malinskiy/action-android that referenced this pull request Nov 22, 2020
Clarify the purpose of each step, and add a missing step that's needed for ADB to work correctly (``sdkmanager platform-tools``) per https://github.com/Malinskiy/action-android/blob/5c20fa7/.github/workflows/test-macos.yml#L16 and #22 (comment).

I noticed this when trying to get oppia/oppia-android#1844 to work.
@BenHenning
Copy link
Member Author

From talking to folks this week, I'm thinking about repurposing this PR to focus on just running a few of the essential test suites, specifically:

  • HomeActivityTest
  • StateFragmentTest
  • One of the profile test suites

This is far from comprehensive, but it at least introduces some CI coverage for key scenarios to offset the very long test runs. I'll probably wait until #1904 is merged, first (due to both PRs significantly impacting CI load).

@BenHenning BenHenning added the PR don't merge - NEEDS UPDATE Corresponds to PRs that need to be updated with the latest develop changes before they can be merged label Feb 24, 2021
@BenHenning
Copy link
Member Author

Due to lack of time to work on this, and the desire to use a cloud platform for Espresso tests, closing this for now (though it still may be a nice reference).

@BenHenning BenHenning closed this Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR don't merge - NEEDS UPDATE Corresponds to PRs that need to be updated with the latest develop changes before they can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Espresso video recording to CI [Blocked: #1831]
1 participant