Repository navigation
test(state): replace file-scope test_ctx with per-test fixture - #42
Merged
Merged
Conversation
Convert all 126 TEST() macros in state_test.cpp to TEST_F(StateTestFixture, ...). Each test now gets a fresh cvc::app, isolating per-test state roots instead of sharing the file-scope 'static cvc::app test_ctx;' crutch. - Add StateTestFixture with a per-test cvc::app ctx member. - Convert lambda bodies that reference ctx to capture 'this'. - Give the GuardedCallback helper struct an explicit cvc::app& reference so its operator() can reach the fixture's ctx. All 126 StateTestFixture cases pass locally (1 perf case skipped).
The HDF5Test fixture's temp dir was '/<binary_dir>/hdf5_test_<thread_id>'. Each ctest case is a separate process invocation but std::this_thread::get_id() for the main thread is frequently reused across freshly-spawned processes on macOS, so parallel ctest workers were colliding on the same on-disk directory and stomping each other's H5 files. That surfaced as flaky 'unknown file: Failure' / 'objectExists() == false' failures on test/macos-latest/Release for PR #42 even though the master baseline already includes the H5F_SCOPE_GLOBAL flush fix from #41. Make the directory name include the process id, an atomic per-process counter, and a steady_clock timestamp in addition to the thread id, so no two test instances (within or across processes) can collide. Wrap getpid() in a portable shim (process.h::_getpid on Windows, unistd.h::getpid elsewhere).
transfix
added a commit
that referenced
this pull request
May 5, 2026
The HDF5Test fixture's temp dir was '/<binary_dir>/hdf5_test_<thread_id>'. Each ctest case is a separate process invocation but std::this_thread::get_id() for the main thread is frequently reused across freshly-spawned processes on macOS, so parallel ctest workers were colliding on the same on-disk directory and stomping each other's H5 files. That surfaced as flaky 'unknown file: Failure' / 'objectExists() == false' failures on test/macos-latest/Release for PR #42 even though the master baseline already includes the H5F_SCOPE_GLOBAL flush fix from #41. Make the directory name include the process id, an atomic per-process counter, and a steady_clock timestamp in addition to the thread id, so no two test instances (within or across processes) can collide. Wrap getpid() in a portable shim (process.h::_getpid on Windows, unistd.h::getpid elsewhere).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Convert all TEST() macros in
state_test.cpptoTEST_F(StateTestFixture, ...). Each test now gets a freshcvc::appso its per-app state root is isolated, replacing the previous file-scopestatic cvc::app test_ctx;shared-root crutch.Why
The shared file-scope
cvc::appmeant tests inherited mutations from prior tests in the file, masking ordering bugs and making failures non-reproducible in isolation. With a per-test fixture, every case starts from a clean state root.Changes
StateTestFixturewithcvc::app ctxmember.TEST(StateTest, ...)→TEST_F(StateTestFixture, ...);test_ctxreferences →ctx.ctxnow capturethis.GuardedCallbackhelper struct takes an explicitcvc::app&so itsoperator()can reach the fixture'sctx.Verification
(
StateTestFixture.PerformanceHierarchyBenchmarkskipped as before.)Follow-up to the singleton-removal phase D work.