Back to Mongo

Resmoke Bazel Rules

bazel/resmoke/README.md

3.6.17-windows-splunk-v37.3 KB
Original Source

Resmoke Bazel Rules

Rules for running resmoke test suites in Bazel.

resmoke_suite_test

Runs a resmoke test suite in Bazel.

This rule generates a resmoke configuration file based on the provided test sources and base config, then executes the tests using the resmoke.py test runner.

EXAMPLE

bzl
load("//bazel/resmoke:resmoke.bzl", "resmoke_suite_test")

resmoke_suite_test(
    name = "jscore",
    config = "//buildscripts/resmokeconfig/suites:core.yml",
    srcs = ["//jstests/core:all_subpackage_javascript_files"],
    exclude_with_any_tags = ["requires_sharding"],
    deps = [
        "//src/mongo/db:mongod",
        "//src/mongo/shell:mongo",
    ],
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this test target.<a href="https://bazel.build/concepts/labels#target-names">Name</a>required
configThe base resmoke YAML configuration file for the suite. This provides the default configuration that will be augmented with the selected tests.<a href="https://bazel.build/concepts/labels">Label</a>required
srcsTest files to include in the suite. These files are written as the 'roots' of the test selector in the generated configuration. Typically JavaScript test files for jstest suites.<a href="https://bazel.build/concepts/labels">List of labels</a>required
dataAdditional files required by the tests during runtime. Typically JavaScript files from jstests/libs.<a href="https://bazel.build/concepts/labels">List of labels</a>optional[]
depsMongoDB binaries and other executables that the tests depend on (e.g., mongod, mongos). These are placed on the PATH when running the test suite.<a href="https://bazel.build/concepts/labels">List of labels</a>optional[]
exclude_filesTest files to explicitly exclude from the suite, even if they appear in srcs.<a href="https://bazel.build/concepts/labels">List of labels</a>optional[]
exclude_with_any_tagsList of test tags. Tests with any of these tags will be excluded from the suite.List of stringsoptional[]
include_with_any_tagsList of test tags. Only tests with at least one of these tags will be included in the suite.List of stringsoptional[]
resmoke_argsAdditional command-line arguments to pass to the resmoke runner.List of stringsoptional[]
shard_countThe number of parallel shards to split the test suite across. Each shard runs a subset of the tests. See the Test Sharding section below for details.IntegeroptionalNone
group_sizeNumber of tests to run in each group. Only applicable for test_kind: parallel_fsm_workload_test suites.IntegeroptionalNone
group_count_multiplierMultiplier for the number of groups. Only applicable for test_kind: parallel_fsm_workload_test suites. Should be a float value passed as a string (e.g., "2.5").Stringoptional""

Test Sharding

Test sharding allows you to split a large test suite across multiple parallel test executions, significantly reducing total test time. When shard_count is specified, Bazel will:

  1. Run the test target multiple times in parallel (up to the specified shard count)
  2. Each shard receives a unique shard index (0 to N-1)
  3. The resmoke runner uses these values to determine which subset of tests to run in each shard
  4. Each shard produces its own test output and logs

Note: sharding is an alternative to the resmoke --jobs flag, which should not be used with resmoke_suite_test.

Test Logs and Output Directory

Bazel creates a dedicated output directory for each test run under the bazel-testlogs symlink in your workspace root.

For a test target //buildscripts/resmokeconfig:core, the outputs are like:

bazel-testlogs/buildscripts/resmokeconfig/core/
├── test.log                           # Primary test output log. Contains the output of resmoke.py
├── test.outputs/
│   ├── report.json                    # Test results in JSON format
│   ├── resource_usage.txt             # Periodically recorded resource usage metrics
│   └── data/                          # The data directory for the resmoke fixture
│       └── job0/
│           ├── mongorunner/
│           └── resmoke/
│               ├── WiredTiger*
│               ├── journal/
│               └── diagnostic.data/

Useful commands

Run a single test from a suite:

bazel test //buildscripts/resmokeconfig:core --test_sharding_strategy=disabled --test_arg=jstests/core/js/jssymbol.js

Run with additional resmoke flags:

Any --test_arg in the bazel command will be propagated as a flag to resmoke.py. To modify the resmoke invocation with any of resmoke's flags, add them as --test_args.

# Runs all tests from the core suite with timeseries in their name, twice, with all feature flags enabled.

bazel test //buildscripts/resmokeconfig:core \
--test_sharding_strategy=disabled \
--test_arg=--repeatTests=2 \
--test_arg=--runAllFeatureFlagTests \
--test_arg=--skipExcludedTests \
`fdfind -t f --full-path ".timeseries\.js$" jstests/core | awk '{print "--test_arg=" $0}'`

Run resmoke.py outside of bazel with the suite's config:

# Build binaries and the suite's config (the *_config target)
bazel build install-dist-test //buildscripts/resmokeconfig:core_config

python buildscripts/resmoke.py run --suite bazel-bin/buildscripts/resmokeconfig/core.yml