我如何要求 Bazel 重新运行缓存测试?
How can I ask Bazel to rerun a cached test?
我正在尝试分析和修复一个经常呈绿色的不稳定测试。
我的问题是,一旦测试通过,Bazel 不会重新运行它,直到任何输入发生变化。
我看到你可以要求 Bazel 重新 运行 一个目标,但 AFAICT 直到第一次它是绿色的(即减轻不稳定的测试而不是解决它)。
有没有办法让 Bazel 运行 即使测试通过了?
我想要 bazel test --force-attempts=50 //my-package:my-target
它有一个标志
--cache_test_results=(yes|no|auto) (-t)
If this option is set to 'auto' (the default) then Bazel will only rerun a test if any of the following conditions applies:
- Bazel detects changes in the test or its dependencies
- the test is marked as
external
- multiple test runs were requested with
--runs_per_test
the test failed.
If 'no', all tests will be executed unconditionally.
If 'yes', the caching behavior will be the same as auto except that it may cache test failures and test runs with --runs_per_test
.
Note that test results are always saved in Bazel's output tree, regardless of whether this option is enabled, so you needn't have used --cache_test_results
on the prior run(s) of bazel test
in order to get cache hits. The option only affects whether Bazel will use previously saved results, not whether it will save results of the current run.
Users who have enabled this option by default in their .bazelrc
file may find the abbreviations -t
(on) or -t-
(off) convenient for overriding the default on a particular run.
https://docs.bazel.build/versions/master/user-manual.html#flag--cache_test_results
除了 --cache_test_results
, Bazel actually has a flag specifically designed for diagnosing flaky tests: --runs_per_test
,它将重新运行测试 N 次并且只保留失败运行的日志:
$ bazel test --runs_per_test=10 :flaker
INFO: Found 1 test target...
FAIL: //:flaker (run 10 of 10) (see /output/testlogs/flaker/test_run_10_of_10.log).
FAIL: //:flaker (run 4 of 10) (see /output/testlogs/flaker/test_run_4_of_10.log).
FAIL: //:flaker (run 5 of 10) (see /output/testlogs/flaker/test_run_5_of_10.log).
FAIL: //:flaker (run 9 of 10) (see /output/testlogs/flaker/test_run_9_of_10.log).
FAIL: //:flaker (run 3 of 10) (see /output/testlogs/flaker/test_run_3_of_10.log).
Target //:flaker up-to-date:
bazel-bin/flaker
INFO: Elapsed time: 0.828s, Critical Path: 0.42s
//:flaker FAILED
Executed 1 out of 1 tests: 1 fails locally.
您可以使用它来快速找出测试的不稳定程度并获取一些失败的日志。
我正在尝试分析和修复一个经常呈绿色的不稳定测试。
我的问题是,一旦测试通过,Bazel 不会重新运行它,直到任何输入发生变化。
我看到你可以要求 Bazel 重新 运行 一个目标,但 AFAICT 直到第一次它是绿色的(即减轻不稳定的测试而不是解决它)。
有没有办法让 Bazel 运行 即使测试通过了?
我想要 bazel test --force-attempts=50 //my-package:my-target
它有一个标志
--cache_test_results=(yes|no|auto) (-t)
If this option is set to 'auto' (the default) then Bazel will only rerun a test if any of the following conditions applies:
- Bazel detects changes in the test or its dependencies
- the test is marked as
external
- multiple test runs were requested with
--runs_per_test
the test failed. If 'no', all tests will be executed unconditionally.If 'yes', the caching behavior will be the same as auto except that it may cache test failures and test runs with
--runs_per_test
.Note that test results are always saved in Bazel's output tree, regardless of whether this option is enabled, so you needn't have used
--cache_test_results
on the prior run(s) ofbazel test
in order to get cache hits. The option only affects whether Bazel will use previously saved results, not whether it will save results of the current run.Users who have enabled this option by default in their
.bazelrc
file may find the abbreviations-t
(on) or-t-
(off) convenient for overriding the default on a particular run.
https://docs.bazel.build/versions/master/user-manual.html#flag--cache_test_results
除了 --cache_test_results
, Bazel actually has a flag specifically designed for diagnosing flaky tests: --runs_per_test
,它将重新运行测试 N 次并且只保留失败运行的日志:
$ bazel test --runs_per_test=10 :flaker
INFO: Found 1 test target...
FAIL: //:flaker (run 10 of 10) (see /output/testlogs/flaker/test_run_10_of_10.log).
FAIL: //:flaker (run 4 of 10) (see /output/testlogs/flaker/test_run_4_of_10.log).
FAIL: //:flaker (run 5 of 10) (see /output/testlogs/flaker/test_run_5_of_10.log).
FAIL: //:flaker (run 9 of 10) (see /output/testlogs/flaker/test_run_9_of_10.log).
FAIL: //:flaker (run 3 of 10) (see /output/testlogs/flaker/test_run_3_of_10.log).
Target //:flaker up-to-date:
bazel-bin/flaker
INFO: Elapsed time: 0.828s, Critical Path: 0.42s
//:flaker FAILED
Executed 1 out of 1 tests: 1 fails locally.
您可以使用它来快速找出测试的不稳定程度并获取一些失败的日志。