Skip to main content
Bazel runs test actions in parallel, sized to the machine’s CPU and memory. A test that needs more than its share, such as one using a GPU or a large dataset, can run out of memory when others run beside it, and fail only sometimes. Tell Bazel what the test needs, and it schedules fewer actions around it. Start with the narrowest control that fixes the failures, and widen only if you need to.

Run a test alone: exclusive

The exclusive tag makes Bazel run the test with no other build or test action on the machine. Use it when a few specific tests consume far more than the rest.
BUILD.bazel

Reserve CPU slots: cpu:N

The cpu:N tag reserves N CPU slots for the test. A higher N leaves fewer slots for other actions on the same machine, so it doubles as a memory reservation. Use it when exclusive is too restrictive and you want to tune how much concurrency to give up.
BUILD.bazel

Declare a custom resource: resources:<name>:<amount>

For a resource Bazel doesn’t count, such as GPUs, declare how many the machine has and how many each test uses. Bazel then never runs more tests at once than the machine can hold.
BUILD.bazel
.bazelrc

Limit concurrency for the whole build

These flags affect every action, and are usually more than a few problematic tests need. Consider them when a large part of your test suite is resource-intensive.