Ray's Knowledge Base

CTest tests that run a build in the build tree must share RESOURCE_LOCK build_tree

PitfallVerified 27 Sep 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

With ctest --preset tests -j8, a test that runs a build in the build tree fails at random, while it passes alone. The log of the build tree is corrupted.

Cause#

Some tests do not run a test binary but invoke a build in the same build tree: schema_class_bad_member builds a target that must fail to compile (it checks for the text "schema class members must be index::Field"), and c_abi_guard builds too. When CTest runs two of them at once, two builds write the same build tree and its log at the same time.

Fix#

Give every test that runs a build in the build tree the same resource lock, so CTest never runs two of them at once:

# Both tests run a build in this build tree; two at once corrupt its log.
set_tests_properties(
  schema_class_bad_member
  PROPERTIES PASS_REGULAR_EXPRESSION
             "schema class members must be index::Field"
             RESOURCE_LOCK build_tree)
set_tests_properties(c_abi_guard PROPERTIES RESOURCE_LOCK build_tree)

Add the lock to any new test of this kind.

Evidence#

  • tests/CMakeLists.txt in dftracer-utils, added in stage 7b after a concurrent build collided with a parallel ctest run.