Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ask Bazel to rerun a cached test?

Tags:

bazel

I'm trying to analyze and fix a flaky test which is often green.
My problem is that once the test passes Bazel doesn't re-run it until any of the inputs have changed.
I saw you can ask Bazel to re-run a target but AFAICT it's only until the first time it's green (i.e. to mitigate a flaky test and not solve it).

Is there a way to ask Bazel to run the test even if it passed?
I'd like something like bazel test --force-attempts=50 //my-package:my-target

like image 685
Ittai Avatar asked Jun 25 '17 08:06

Ittai


People also ask

How does Bazel caching work?

Bazel checks your local machine for existing build outputs and reuses any that it finds. Bazel checks the cache for existing build outputs. If the output is found, Bazel retrieves the output. This is a cache hit.

How do you test with Bazel?

Using a test target The most straightforward way to validate an artifact is to write a script and add a *_test target to your BUILD file. The specific artifacts you want to check should be data dependencies of this target.

What does Bazel run do?

Bazel is a tool that automates software builds and tests. Supported build tasks include running compilers and linkers to produce executable programs and libraries, and assembling deployable packages for Android, iOS and other target environments.


1 Answers

There's a flag for it

--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

like image 174
Ittai Avatar answered Sep 29 '22 02:09

Ittai