Skip to content

Commit 18d8be4

Browse files
authored
Shard integration tests (#1350)
1 parent b7a524f commit 18d8be4

File tree

3 files changed

+87
-54
lines changed

3 files changed

+87
-54
lines changed

.bazelci/presubmit.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ matrix:
66
integration_platform:
77
- ubuntu2404
88
- ubuntu2204
9+
integration_shard_flags:
10+
- ["--test_tag_filters=shard_0", "--config=rbe"]
11+
- ["--test_tag_filters=shard_1", "--config=rbe"]
12+
- ["--test_tag_filters=shard_2", "--config=rbe"]
913
# - macos
1014
# - windows re-enable when rules_bazel_integration_test can support custom test runner on windows.
1115
test_flags:
@@ -30,8 +34,7 @@ tasks:
3034
integration_tests:
3135
name: "Integration Tests"
3236
platform: ${{ integration_platform }}
33-
test_flags:
34-
- "--config=rbe"
37+
test_flags: ${{ integration_shard_flags }}
3538
test_targets:
3639
- //examples:all
3740
rbe_ubuntu1604:

examples/BUILD

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
2-
load(
3-
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
4-
"bazel_integration_tests",
5-
)
1+
load(":integration.bzl", "derive_metadata", "example_integration_test_suite")
62

73
genrule(
84
name = "update_bit_ignore",
@@ -21,54 +17,23 @@ genrule(
2117
executable = True,
2218
)
2319

20+
SHARD_COUNT = 3
21+
2422
[
25-
bazel_integration_tests(
26-
name = "%s_test" % example,
27-
timeout = "eternal",
28-
additional_env_inherit = [
29-
"ANDROID_HOME",
30-
"ANDROID_SDK_ROOT",
31-
"ANDROID_NDK_HOME",
32-
],
33-
bazel_versions = [
34-
version
35-
for version in bazel_binaries.versions.all
36-
if version in metadata["only"] or (not metadata["only"] and version not in metadata["exclude"])
37-
],
38-
tags = [],
39-
test_runner = "//src/main/kotlin/io/bazel/kotlin/test:BazelIntegrationTestRunner",
40-
workspace_files = glob(
41-
["%s/**/**" % example],
42-
# exclude any bazel directories if existing
43-
exclude = ["%s/bazel-*/**" % example],
44-
),
45-
workspace_path = example,
23+
example_integration_test_suite(
24+
name = example,
25+
metadata = metadata,
26+
tags = ["shard_%s" % (idx % SHARD_COUNT)],
4627
)
47-
for (example, metadata) in {
48-
example: {
49-
"exclude": [
50-
# Cut to the file name, and use it as an excluded bazel version. For exclusion to work
51-
# the file name in the `exclude` directory must match the bazel version in `bazel_binaries.versions.all`.
52-
# This is done as a secondary loop for readability and avoiding over-globbing.
53-
version.rpartition("/")[2]
54-
for version in glob(
55-
["%s/exclude/*" % example],
56-
allow_empty = True,
57-
)
58-
],
59-
"only": [
60-
# Cut to the file name, and use it as an only bazel version. For exclusion to work
61-
# the file name in the `only` directory must match the bazel version in `bazel_binaries.versions.all`.
62-
# This is done as a secondary loop for readability and avoiding over-globbing.
63-
version.rpartition("/")[2]
64-
for version in glob(
65-
["%s/only/*" % example],
66-
allow_empty = True,
67-
)
68-
],
69-
}
28+
for (
29+
idx,
30+
(example, metadata),
31+
) in enumerate({
32+
example: derive_metadata(
33+
directory = example,
34+
)
7035
for example in {
71-
# Cut to the directory.
36+
# Cut to the directory, de-duplicate via dict.
7237
file.partition("/")[0]: True
7338
for file in glob(
7439
["**/*"],
@@ -77,10 +42,10 @@ genrule(
7742
"*",
7843
# Node is currently broken.
7944
"node/**",
80-
# Anvil is broken by a verison upgrade.
45+
# Anvil is broken by a version upgrade.
8146
"anvil/**",
8247
],
8348
)
8449
}
85-
}.items()
50+
}.items())
8651
]

examples/integration.bzl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Macros for managing the integration test framework."""
2+
3+
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
4+
load(
5+
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
6+
"bazel_integration_test",
7+
)
8+
9+
def derive_metadata(directory):
10+
return struct(
11+
directory = directory,
12+
workspace_files = native.glob(
13+
["%s/**/**" % directory],
14+
# exclude any bazel directories if existing
15+
exclude = ["%s/bazel-*/**" % directory],
16+
),
17+
exclude = [
18+
# Cut to the file name, and use it as an excluded bazel version. For exclusion to work
19+
# the file name in the `exclude` directory must match the bazel version in `bazel_binaries.versions.all`.
20+
# This is done as a secondary loop for readability and avoiding over-globbing.
21+
version.rpartition("/")[2]
22+
for version in native.glob(
23+
["%s/exclude/*" % directory],
24+
allow_empty = True,
25+
)
26+
],
27+
only = [
28+
# Cut to the file name, and use it as an only bazel version. For exclusion to work
29+
# the file name in the `only` directory must match the bazel version in `bazel_binaries.versions.all`.
30+
# This is done as a secondary loop for readability and avoiding over-globbing.
31+
version.rpartition("/")[2]
32+
for version in native.glob(
33+
["%s/only/*" % directory],
34+
allow_empty = True,
35+
)
36+
],
37+
)
38+
39+
def example_integration_test_suite(
40+
name,
41+
metadata,
42+
tags):
43+
for version in bazel_binaries.versions.all:
44+
if version in metadata.only or (not metadata.only and version not in metadata.exclude):
45+
clean_bazel_version = Label(version).name
46+
test_name = "%s_%s_test" % (name, clean_bazel_version)
47+
bazel_integration_test(
48+
name = test_name,
49+
timeout = "eternal",
50+
additional_env_inherit = [
51+
"ANDROID_HOME",
52+
"ANDROID_SDK_ROOT",
53+
"ANDROID_NDK_HOME",
54+
],
55+
bazel_version = version,
56+
tags = tags + [clean_bazel_version, name],
57+
test_runner = "//src/main/kotlin/io/bazel/kotlin/test:BazelIntegrationTestRunner",
58+
workspace_files = metadata.workspace_files,
59+
workspace_path = metadata.directory,
60+
)
61+
62+
native.test_suite(
63+
name = name,
64+
tags = [name],
65+
)

0 commit comments

Comments
 (0)