Skip to content

Commit

Permalink
Split grouped tests by Feature annotation
Browse files Browse the repository at this point in the history
Feature flags in instrumentation tests only change when Chrome is
restarted. To allow to run tests in Batches that have methods with
@Features annotation, split tests into groups based on enabled/disabled
Features by adding a Batch.SplitByFeature annotation.

Bug: 1170735
Change-Id: Id90d704bcd949eb8630172ed1051cb3fdfc5435f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2645136
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: benjamin joyce <bjoyce@chromium.org>
Reviewed-by: Rohit Agarwal <roagarwal@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#848181}
  • Loading branch information
xchrdw authored and Chromium LUCI CQ committed Jan 28, 2021
1 parent 9e4a469 commit 0a8fc39
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Batch {
/**
* This annotation can be added in addition to @Batch to split batches based on @Features
* annotation. This will ensure that native features are configured correctly.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SplitByFeature {}

public String value();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,23 @@ def _GroupTests(self, tests):
batched_tests = dict()
other_tests = []
for test in tests:
if 'Batch' in test['annotations'] and 'RequiresRestart' not in test[
'annotations']:
batch_name = test['annotations']['Batch']['value']
annotations = test['annotations']
if 'Batch' in annotations and 'RequiresRestart' not in annotations:
batch_name = annotations['Batch']['value']
if not batch_name:
batch_name = test['class']

# Feature flags won't work in instrumentation tests unless the activity
# is restarted.
# Tests with identical features are grouped to minimize restarts.
if 'Batch$SplitByFeature' in annotations:
if 'Features$EnableFeatures' in annotations:
batch_name += '|enabled:' + ','.join(
sorted(annotations['Features$EnableFeatures']['value']))
if 'Features$DisableFeatures' in annotations:
batch_name += '|disabled:' + ','.join(
sorted(annotations['Features$DisableFeatures']['value']))

if not batch_name in batched_tests:
batched_tests[batch_name] = []
batched_tests[batch_name].append(test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.chromium.base.test.UiThreadTest;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RequiresRestart;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.profiles.Profile;
Expand All @@ -39,6 +38,7 @@
*/
@RunWith(BaseJUnit4ClassRunner.class)
@Batch(Batch.PER_CLASS)
@Batch.SplitByFeature
public class BookmarkBridgeTest {
@Rule
public final ChromeBrowserTestRule mChromeBrowserTestRule = new ChromeBrowserTestRule();
Expand Down Expand Up @@ -332,7 +332,6 @@ public void testSearch_MaxResults() {
@SmallTest
@UiThreadTest
@Features.EnableFeatures({ChromeFeatureList.READ_LATER})
@RequiresRestart
public void testAddToReadingList() {
Assert.assertNull("Should return null for non http/https URLs.",
mBookmarkBridge.addToReadingList("a", new GURL("chrome://flags")));
Expand Down
4 changes: 4 additions & 0 deletions docs/testing/batching_instrumentation_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ will run the suite in its own batch. This will reduce the complexity of managing
and leaking state from these tests as you only have to think about tests within
the suite. For smaller and less complex test suites, see Custom below.

If you use different @Features annotations on test methods, you can use the
@Batch.SplitByFeature annotation to run tests with different features in
separate batches.

### Custom

This batching type is best for smaller and less complex test suites, that
Expand Down

0 comments on commit 0a8fc39

Please sign in to comment.