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

Introduce tests sharding #21101

Merged
merged 23 commits into from
Aug 9, 2024
Merged

Introduce tests sharding #21101

merged 23 commits into from
Aug 9, 2024

Conversation

wzieba
Copy link
Contributor

@wzieba wzieba commented Jul 31, 2024

Description

This PR implements instrumentation tests sharding using Fladle Gradle Plugin. Comparing to the WooCommerce Android configuration (woocommerce/woocommerce-android#12029) it has some twists:

Impact

Duration of execution of instrumented tests

Jetpack WordPress
Before (b5a72e3) 8m 39s 6m 17s
After 2m 2s 2m 9s
Diff -76.5% -66%

Testing

I've rerun the whole job several times to make sure that tests aren't flaky. We shouldn't expect any difference in tests execution though, as we only distribute tests across few devices, instead of running all of them on a single device.

Demo

image

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 31, 2024

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21101-40986a8
Commit40986a8
Direct Downloadjetpack-prototype-build-pr21101-40986a8.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 31, 2024

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21101-9c05ddd
Commit9c05ddd
Direct Downloadwordpress-prototype-build-pr21101-9c05ddd.apk
Note: Google Login is not supported on these builds.

wzieba added 4 commits July 31, 2024 13:26
Setting `variant` under `configs` doesn't seem to work: runningcode/fladle#60
Copy recursively, as now there'll be multiple xml file reports
As tests between `wordpress` and `jetpack` can differ. A good example is `StatsTests#e2eAllDayStatsLoad` which runs for Jetpack app only.
@wzieba wzieba force-pushed the introduce_tests_sharding branch from 094a51e to 6240d49 Compare August 1, 2024 08:12
Instead of relying on env variable used by previously used Fastlane Firebase action, we'll parse report generated by fladle/flank
@wzieba wzieba force-pushed the introduce_tests_sharding branch from 6240d49 to d00c6b6 Compare August 1, 2024 08:13
@wzieba wzieba force-pushed the introduce_tests_sharding branch from d00c6b6 to cd01ef0 Compare August 1, 2024 08:40
sh("buildkite-agent annotation remove --context '#{annotation_ctx}' || true") if is_ci?
else
details_url = lane_context[SharedValues::FIREBASE_TEST_MORE_DETAILS_URL]
rescue
Copy link
Collaborator

@dangermattic dangermattic Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 Style/RescueStandardError: Avoid rescuing without specifying an error class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iangmaia could you please confirm if it's okay to ignore? I want to rescue from all possible causes of gradle or sh crash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those would still be caught if using rescue StandardError?

Suggested change
rescue
rescue StandardError

By the way, mentioning just in case (not sure if it would make more sense here, as you also have the gradle call): for sh, you can also use a error_callback parameter if you want to do a custom handling in case the command returns an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, rescue StandardError worked fine, thanks! Addressed in 997e808

About error_callback - I don't see it being mentioned in gradle action documentation, and Gradle part is the most crucial part of this handling so I think we could keep this try/catch approach

wzieba added 5 commits August 1, 2024 11:04
 "every action and every plugin's code runs in the root of the project, while all user code from the Fastfile runs inside the ./fastlane directory." https://docs.fastlane.tools/advanced/fastlane/\#directory-behavior
This should fix annotating test failures.
@wzieba wzieba force-pushed the introduce_tests_sharding branch from 13176ae to cc83564 Compare August 1, 2024 11:02
wzieba added 3 commits August 1, 2024 15:44
These tests are ignored anyway during a runtime by `assume` method. This doesn't work well with tests sharding though. In case if one of `e2eAllDayStatsLoad` tests is added on its own to a separate shard, Firebase Test Lab will mark the test suite as failed with message:

"Some test executions didn't run any test cases.
 This is usually caused by aggressive sharding (e.g. more shards than test cases), manual sharding errors, or skipping tests.
 All executions have overhead time, so these may be billable or may count against your quota. A failure outcome was generated to bring your attention to this."
So the config in `wordpress` can indeed append new exclusions
@wzieba wzieba force-pushed the introduce_tests_sharding branch from 7f9f125 to 10c9a74 Compare August 1, 2024 15:59
@wzieba wzieba added [Type] Enhancement UI Tests Anything related to automated UI Tests. labels Aug 2, 2024
@wzieba wzieba added this to the 25.5 milestone Aug 2, 2024
@wzieba wzieba marked this pull request as ready for review August 2, 2024 09:14
@wzieba wzieba requested review from ParaskP7 and jostnes August 2, 2024 09:14
fastlane/lanes/test.rb Outdated Show resolved Hide resolved
Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.39%. Comparing base (2069f57) to head (e7d901b).
Report is 38 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #21101      +/-   ##
==========================================
- Coverage   40.71%   40.39%   -0.33%     
==========================================
  Files        1530     1515      -15     
  Lines       70256    69722     -534     
  Branches    11612    11562      -50     
==========================================
- Hits        28606    28165     -441     
+ Misses      39065    38990      -75     
+ Partials     2585     2567      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +30 to +31
"notClass org.wordpress.android.e2e.StatsTests",
"notClass org.wordpress.android.e2e.StatsGranularTabsTest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for test targets unavailable on the variant, do we need to define them here to be excluded?

asking because when looking at the tests, it looks like there's a check to see if it's jetpack app before continuing with test setup:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, they have to. If they're not, fladle/flank might create a shard with only tests from StatsTests or StatsGranularTabsTest. As they're ignored, the execution will be very fast (few seconds) and Firebase Test Lab will mark the test run as failed. It will do this to signal a problem, as too aggressive sharding might bring more unwanted costs. Some more details are available in here the comment description: cc4cc3b . Failed run like this can be found here https://buildkite.com/automattic/wordpress-android/builds/19467#01910e2f-5783-4f74-8897-2725f66ce343

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the detailed explanation and linking that commit's comment description! What do you think about adding a comment on the test too? So we would know for a future test that's only available on one variant we should add it to the exclusion list too

Copy link
Contributor Author

@wzieba wzieba Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, added a comment! WDYT?

9c05ddd

@wzieba wzieba added the Do Not Merge In PRs with this label, our automation will fail a require check, preventing accidental merging label Aug 5, 2024
Copy link
Contributor

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @wzieba !

I have reviewed this PR and everything LGTM, once again, a really awesome job done here, kudos! 🌟 x 🌟 ^ 🌟

  1. Thanks for making fladle work with a project structure on multiple apps, I am sure it mustn't have been easy! 💯
  2. Thanks for keeping the Firebase annotation! 🥇

I have left one questions (❓), one suggestions (💡) and one minor (🔍) comment for you to consider. I am going to approve this PR anyway, since none is blocking. I am NOT going to merge this PR yet to give you some time to apply any of my suggestions. However, feel free to ignore them and merge the PR yourself.

fastlane/lanes/test.rb Show resolved Hide resolved
WordPress/build.gradle Outdated Show resolved Hide resolved
WordPress/build.gradle Show resolved Hide resolved
WordPress/build.gradle Outdated Show resolved Hide resolved
@wzieba wzieba modified the milestones: 25.5, Future Aug 5, 2024
@wzieba wzieba removed the Do Not Merge In PRs with this label, our automation will fail a require check, preventing accidental merging label Aug 9, 2024
@wzieba wzieba enabled auto-merge August 9, 2024 16:52
Copy link

sonarqubecloud bot commented Aug 9, 2024

@wzieba wzieba merged commit 206f726 into trunk Aug 9, 2024
18 of 20 checks passed
@wzieba wzieba deleted the introduce_tests_sharding branch August 9, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement UI Tests Anything related to automated UI Tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants