-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add new option --treat_no_test_targets_found_as_success_return_code #11465
Comments
Some people unconditionally add an always-passing test to their command line as a workaround. |
The way it is currently implemented to detect test targets is error prone. In case of find-owners plugin there are two test targets: $ grep -2 junit_tests BUILD | grep -o 'name = "[^"]*"' | cut -d '"' -f 2 findowners_junit_tests findowners_IT_tests But the code assumes that there are only one single target: if [ "$TEST_TARGET" != "" ] then bazelisk test --test_env DOCKER_HOST=$DOCKER_HOST plugins/{name}:$TEST_TARGET fi And this is why the second target findowners_IT_tests gets orphaned and is not prefixed with "plugins/{name}" prefix and thus not found. Moreover, this approach to grep for targets can also lead to false negative results, because the test rules might be located in nested plugin packages but not in the root package, like it is the case for checks plugin. For such plugins no test are executed at all. To rectify, avoid grep and just use Bazel's native wildcard "/..." target feature, that should work in all three possible cases: 1. no test rule exist 2. one single test rule exsits in plugin's root package 3. many test rules exist in root and/or nested packages This approach has problem with exit code of bazel in case that there are no tests even thoufg test run was requested. As documented in the user guide: [1], it is expected that Bazel unconditionally returns exit code 4 in this situation. Check for that exit code explicitly and warn CI users to contact plugin maintainers if there were no tests found. Let's face it: the code is inherently broken if there are no tests at all. Still we would like to avoid the boilerplate to be needed and wrote this feature request: [2]. [1] https://docs.bazel.build/versions/master/guide.html#what-exit-code-will-i-get [2] bazelbuild/bazel#11465 Bug: Issue 12512 Change-Id: Id641cfd2300939d3eac5adb4cdc4a14b12d5f7c2
Should the CI manipulate BUILD files for SUT to achieve that workaround or what exactly do you mean by: "to their command line"? Do you have code pointer for me? |
I believe @ulfjack's suggestion was to do
@davido It seems to me from your script that you are making use of the 4 result
I am not keen on a separate flag for changing the result. Instead I would like to see "no tests found" integrated with the work for skipping non-applicable test targets. So you would ask for a structured result file saying how many tests were found, skipped, passed, failed. Maybe even we break down skipped into skipped because of configuration non-applicability or skipped because of filtering. |
Thanks for this suggestion. |
We don't know whether or not all plugins have test rules, so running a generic command: $ bazelisk test plugins/{name}/... can lead to no tests found outcome, in which case Bazel will return exit code 4 that needs to be checked to differentiate from test failure (exit code 1). To avoid those checks, pass the virtual test that will always succeed: $ bazelisk test //tools/bzl:always_pass_test plugins/{name}/... See also this upstream issue for this suggested workaround: [1]. [1] bazelbuild/bazel#11465 Change-Id: Ideab64674482400cc48fad55f7ed9f8085909b84
As suggested in this upstream issue: [1] use always pass test to avoid Bazel returning exit code 4 and corresponding boilerplate in no tests found use case. [1] bazelbuild/bazel#11465 Change-Id: I3b102d0efae69cf975e0e2787537efc5898d5938
We don't know whether or not all plugins have test rules, so running a generic command: $ bazelisk test plugins/{name}/... can lead to no tests found outcome, in which case Bazel will return exit code 4 that needs to be checked to differentiate from test failure (exit code 1). To avoid those checks, pass the virtual test that will always succeed: $ bazelisk test //tools/bzl:always_pass_test plugins/{name}/... See also this upstream issue for this suggested workaround: [1]. [1] bazelbuild/bazel#11465 Change-Id: Ideab64674482400cc48fad55f7ed9f8085909b84 (cherry picked from commit d69773c)
We don't know whether or not all plugins have test rules, so running a generic command: $ bazelisk test plugins/{name}/... can lead to no tests found outcome, in which case Bazel will return exit code 4 that needs to be checked to differentiate from test failure (exit code 1). To avoid those checks, pass the virtual test that will always succeed: $ bazelisk test //tools/bzl:always_pass_test plugins/{name}/... See also this upstream issue for this suggested workaround: [1]. [1] bazelbuild/bazel#11465 Change-Id: Ideab64674482400cc48fad55f7ed9f8085909b84 (cherry picked from commit d69773c) (cherry picked from commit 938db88)
Right now the code unconditionally returns exit code 4 in this situation, see: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java#L165-L187
The problem is, that this requires some boilerplate on the CI code to differentiate between 0, 1 and 4. Gerrit Code Review has 100+ plugins, and we don't have plugin specific CI configuration, so that we would like to run generic command:
The problem is to handle
NO_TEST_TARGETS
outcome on the CI side:Instead, we would like to be able to just say this:
See this CL for more details: [1].
[1] https://gerrit-review.googlesource.com/c/gerrit-ci-scripts/+/268512
The text was updated successfully, but these errors were encountered: