-
Notifications
You must be signed in to change notification settings - Fork 136
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
Support sharding and regex-based --test_filter
in swift_test
#1410
Open
brentleyjones
wants to merge
1
commit into
master
Choose a base branch
from
bj/test-sharding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`swift_test` targets can now shard their execution using Bazel's standard `shard_count` test attribute. When Bazel runs a sharded test, it spawns _N_ separate actions in parallel where each shard runs a distinct subset of the tests. On both Apple and Linux, this is achieved by looking at the shard count and filtering out a subset of tests. This is straightforward on Linux where we generate the test runner. Making this work with Apple's `xctest` bundle runner would not have been feasible, so we've abandoned that approach and now treat `swift_test` like any other binary rule: we generate a plain executable (wrapped as an `.xctest` "bundle" on macOS, but not a Mach-O bundle type binary) and use `XCTestSuite.default` to access the dynamically discovered tests. From that object, we can recurse down the test suite/test case hierarchy and select the shard's subset to run. This means we also can no longer use `xctest`'s test filtering, so this change reimplements it manually. This turns out to be an improvement, because we can now use regular expressions to perform the filtering instead of being limited to XCTest's less flexible syntax. Tests will be represented with names of the form `ClassName/MethodName`, and `--test_filter` can be a regular expression that matches those. PiperOrigin-RevId: 606703344 (cherry picked from commit 80cdccc, 1b1f348, 51b1d1c, and bf90194) Signed-off-by: Brentley Jones <[email protected]>
brentleyjones
requested review from
BalestraPatrick,
keith,
luispadron,
mattrobmattrob and
thii
as code owners
October 15, 2024 17:05
brentleyjones
referenced
this pull request
Oct 15, 2024
`swift_test` targets can now shard their execution using Bazel's standard `shard_count` test attribute. When Bazel runs a sharded test, it spawns _N_ separate actions in parallel where each shard runs a distinct subset of the tests. On both Apple and Linux, this is achieved by looking at the shard count and filtering out a subset of tests. This is straightforward on Linux where we generate the test runner. Making this work with Apple's `xctest` bundle runner would not have been feasible, so we've abandoned that approach and now treat `swift_test` like any other binary rule: we generate a plain executable (wrapped as an `.xctest` "bundle" on macOS, but not a Mach-O bundle type binary) and use `XCTestSuite.default` to access the dynamically discovered tests. From that object, we can recurse down the test suite/test case hierarchy and select the shard's subset to run. This means we also can no longer use `xctest`'s test filtering, so this change reimplements it manually. This turns out to be an improvement, because we can now use regular expressions to perform the filtering instead of being limited to XCTest's less flexible syntax. Tests will be represented with names of the form `ClassName/MethodName`, and `--test_filter` can be a regular expression that matches those. PiperOrigin-RevId: 606703344
brentleyjones
referenced
this pull request
Oct 15, 2024
…used. Also allow the test filter to match any part of the test name, not just the whole string. Users can explicitly write `^...$` to force a whole string match. PiperOrigin-RevId: 607074089
brentleyjones
referenced
this pull request
Oct 15, 2024
…l to support sharding/filtering. 1) `XCTestSuite.default.run` doesn't automatically exit with a non-zero exit code when tests fail, so even failing tests were counted as passing (!). Handle this manually. 2) If Xcode is installed on the build machine at a different location than the test execution machine, the test binary will fail to load because it has the wrong machine's Xcode path in its rpaths. Weakly link to XCTest and `dlopen` the framework and support dylib at runtime to address this. PiperOrigin-RevId: 609333464
luispadron
approved these changes
Oct 15, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
swift_test
targets can now shard their execution using Bazel's standardshard_count
test attribute. When Bazel runs a sharded test, it spawns N separate actions in parallel where each shard runs a distinct subset of the tests.On both Apple and Linux, this is achieved by looking at the shard count and filtering out a subset of tests. This is straightforward on Linux where we generate the test runner. Making this work with Apple's
xctest
bundle runner would not have been feasible, so we've abandoned that approach and now treatswift_test
like any other binary rule: we generate a plain executable (wrapped as an.xctest
"bundle" on macOS, but not a Mach-O bundle type binary) and useXCTestSuite.default
to access the dynamically discovered tests. From that object, we can recurse down the test suite/test case hierarchy and select the shard's subset to run.This means we also can no longer use
xctest
's test filtering, so this change reimplements it manually. This turns out to be an improvement, because we can now use regular expressions to perform the filtering instead of being limited to XCTest's less flexible syntax. Tests will be represented with names of the formClassName/MethodName
, and--test_filter
can be a regular expression that matches those.PiperOrigin-RevId: 606703344
(cherry picked from commit 80cdccc, 1b1f348, 51b1d1c, and bf90194)