Skip to content

test(cpp): give clock-seeded test files unique per-process names - #1102

Open
ColinLeeo wants to merge 2 commits into
developfrom
test/unique-test-filenames
Open

ColinLeeo wants to merge 2 commits into
developfrom
test/unique-test-filenames

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

Problem

Several test fixtures build their .tsfile name from a clock count alone:

"table_field_filter_" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) +
".tsfile"

CTest runs test cases in parallel processes, so two of them can read the same clock tick and generate the same name. One process then removes the file the other is about to open (or reopens it later), which surfaces as E_ALREADY_EXIST from TsFileWriter::open, E_FILE_OPEN_ERR from WriteFile::open, or a SEGFAULT in a fixture that continues after the failed open.

This has been flaking unrelated PRs (macOS 3.11, MSVC, macOS Release jobs) with failures in TsFileReaderTest.*, TableFieldFilterTest.*, RowAndBatchParallelModes/TableFieldFilterTest.*.

Change

Append the process id and a per-process counter to those names, the same pattern tsfile_writer_test.cc and tsfile_writer_empty_chunk_regression_test.cc already use:

  • table_field_filter_test.cc
  • table_read_failure_test.cc
  • chunk_reader_resource_test.cc
  • aligned_chunk_reader_bulk_test.cc
  • aligned_field_filter_regression_test.cc
  • block/masked_bulk_copy_test.cc
  • timeseries_schema_codec_test.cc

tsfile_reader_test.cc already seeds from std::random_device, so it is left as is.

Testing

Full C++ suite: 1528 tests passed; spotless:check clean.

Several fixtures build their .tsfile name from a clock count alone.  CTest
runs cases in parallel processes, so two can read the same tick and then
one removes the file the other is opening or reopening
(E_ALREADY_EXIST / E_FILE_OPEN_ERR, seen as SEGFAULT on macOS).

Append the process id and a per-process counter, the pattern the writer
tests already use.  Covers table_read_failure, table_field_filter,
chunk_reader_resource, aligned_chunk_reader_bulk,
aligned_field_filter_regression, masked_bulk_copy and
timeseries_schema_codec.
@codecov-commenter

codecov-commenter commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.93%. Comparing base (b16df6b) to head (3f8078b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1102   +/-   ##
========================================
  Coverage    66.93%   66.93%           
========================================
  Files          788      788           
  Lines        57536    57536           
  Branches      9297     9297           
========================================
  Hits         38509    38509           
  Misses       17358    17358           
  Partials      1669     1669           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ColinLeeo
ColinLeeo requested a balanced review from Copilot November 13, 2026 10:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

This PR reduces flaky C++ tests by making temporary .tsfile names unique across parallel CTest processes, preventing cross-process collisions and intermittent open/remove failures.

Changes:

  • Append process id and a per-process counter to test-generated .tsfile names.
  • Add platform-specific PID includes (process.h / unistd.h) and atomics to support uniqueness.
File Description
cpp/​test/​reader/​timeseries_schema_codec_test.cc Adds PID + atomic counter suffix to generated names for cross-process uniqueness.
cpp/​test/​reader/​table_read_failure_test.cc Makes table_read_failure_*.tsfile names unique via PID + counter.
cpp/​test/​reader/​table_field_filter_test.cc Makes table_field_filter_*.tsfile names unique via PID + counter.
cpp/​test/​reader/​chunk_reader_resource_test.cc Extends filename generation to include PID + atomic counter (under thread-enabled build sections).
cpp/​test/​reader/​block/​masked_bulk_copy_test.cc Makes masked_bulk_copy_*.tsfile names unique via PID + counter.
cpp/​test/​reader/​aligned_field_filter_regression_test.cc Makes regression test .tsfile names unique via PID + counter.
cpp/​test/​reader/​aligned_chunk_reader_bulk_test.cc Extends filename generation to include PID + atomic counter (under thread-enabled build sections).

Review effort: Lite

std::chrono::steady_clock::now().time_since_epoch().count()) +
".tsfile";
"_" + std::to_string(process_id) + "_" +
std::to_string(filename_counter.fetch_add(1)) + ".tsfile";
Comment on lines +87 to +88
// CTest runs cases in parallel processes; two can seed from the same
// clock tick and then collide on the file name.
getpid()/_getpid() are used in the fixtures unconditionally, but the
process.h/unistd.h block landed inside the ENABLE_THREADS guard in
aligned_chunk_reader_bulk_test and chunk_reader_resource_test, which
would break a build with threads disabled.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants