Skip to content

test(state): replace file-scope test_ctx with per-test fixture - #42

Merged
transfix merged 2 commits into
masterfrom
tests/state-no-shared-app
May 5, 2026
Merged

transfix merged 2 commits into
masterfrom
tests/state-no-shared-app

Conversation

@transfix

@transfix transfix commented May 5, 2026

Copy link
Copy Markdown
Owner

Convert all TEST() macros in state_test.cpp to TEST_F(StateTestFixture, ...). Each test now gets a fresh cvc::app so its per-app state root is isolated, replacing the previous file-scope static cvc::app test_ctx; shared-root crutch.

Why

The shared file-scope cvc::app meant 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

  • New StateTestFixture with cvc::app ctx member.
  • All 126 TEST(StateTest, ...) → TEST_F(StateTestFixture, ...); test_ctx references → ctx.
  • Lambdas that touch ctx now capture this.
  • GuardedCallback helper struct takes an explicit cvc::app& so its operator() can reach the fixture's ctx.

Verification

ctest -R '^StateTest' --output-on-failure
100% tests passed, 0 tests failed out of 126

(StateTestFixture.PerformanceHierarchyBenchmark skipped as before.)

Follow-up to the singleton-removal phase D work.

transfix added 2 commits May 4, 2026 21:54
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).
@transfix
transfix merged commit 30e00cd into master May 5, 2026
19 checks passed
@transfix
transfix deleted the tests/state-no-shared-app branch May 5, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant