From efc71e26d3c5e514ecb2c4970571f76f2e0887e4 Mon Sep 17 00:00:00 2001 From: ColinLee Date: Fri, 13 Nov 2026 14:53:17 +0800 Subject: [PATCH 1/2] test(cpp): give clock-seeded test files unique names 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. --- .../reader/aligned_chunk_reader_bulk_test.cc | 18 ++++++++++++++++++ .../aligned_field_filter_regression_test.cc | 17 ++++++++++++++++- cpp/test/reader/block/masked_bulk_copy_test.cc | 17 ++++++++++++++++- cpp/test/reader/chunk_reader_resource_test.cc | 17 +++++++++++++++++ cpp/test/reader/table_field_filter_test.cc | 17 ++++++++++++++++- cpp/test/reader/table_read_failure_test.cc | 17 ++++++++++++++++- .../reader/timeseries_schema_codec_test.cc | 17 +++++++++++++++++ 7 files changed, 116 insertions(+), 4 deletions(-) diff --git a/cpp/test/reader/aligned_chunk_reader_bulk_test.cc b/cpp/test/reader/aligned_chunk_reader_bulk_test.cc index 0be62def8..d3efd8796 100644 --- a/cpp/test/reader/aligned_chunk_reader_bulk_test.cc +++ b/cpp/test/reader/aligned_chunk_reader_bulk_test.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,12 @@ #include "writer/tsfile_table_writer.h" #ifdef ENABLE_THREADS #include "common/thread_pool.h" + +#ifdef _WIN32 +#include +#else +#include +#endif #endif using namespace common; @@ -93,6 +100,17 @@ class AlignedBulkCopyTest : public ::testing::Test { "_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + + "_" + std::to_string([] { +#ifdef _WIN32 + return static_cast(_getpid()); +#else + return static_cast(getpid()); +#endif + }()) + + "_" + std::to_string([] { + static std::atomic counter{0}; + return counter.fetch_add(1); + }()) + ".tsfile"; std::remove(path_.c_str()); { diff --git a/cpp/test/reader/aligned_field_filter_regression_test.cc b/cpp/test/reader/aligned_field_filter_regression_test.cc index c2b7506d1..265a075aa 100644 --- a/cpp/test/reader/aligned_field_filter_regression_test.cc +++ b/cpp/test/reader/aligned_field_filter_regression_test.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,12 @@ #include "reader/table_query_executor.h" #include "writer/tsfile_table_writer.h" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace { using namespace common; using namespace storage; @@ -70,11 +77,19 @@ class AlignedFieldFilterRegressionTest saved_ = g_config_value_; g_config_value_.page_writer_max_point_num_ = 3; g_config_value_.parallel_read_enabled_ = std::get<0>(GetParam()); + // Parallel CTest processes can seed from the same clock tick. +#ifdef _WIN32 + const auto process_id = static_cast(_getpid()); +#else + const auto process_id = static_cast(getpid()); +#endif + static std::atomic filename_counter{0}; filename_ = "aligned_field_filter_regression_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + - ".tsfile"; + "_" + std::to_string(process_id) + "_" + + std::to_string(filename_counter.fetch_add(1)) + ".tsfile"; } void TearDown() override { std::remove(filename_.c_str()); diff --git a/cpp/test/reader/block/masked_bulk_copy_test.cc b/cpp/test/reader/block/masked_bulk_copy_test.cc index 21a9e1b50..d2a467a31 100644 --- a/cpp/test/reader/block/masked_bulk_copy_test.cc +++ b/cpp/test/reader/block/masked_bulk_copy_test.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,12 @@ #include "reader/block/single_device_tsblock_reader.h" #include "writer/tsfile_table_writer.h" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace { using namespace common; using namespace storage; @@ -47,11 +54,19 @@ class MaskedBulkCopyTest : public ::testing::TestWithParam { // Source tuple: time + v + n + s + hidden + empty = 72 bytes/row. // Each source TsBlock has 137 rows, crossing two bitmap words. g_config_value_.tsblock_max_memory_ = 72 * 137; + // Parallel CTest processes can seed from the same clock tick. +#ifdef _WIN32 + const auto process_id = static_cast(_getpid()); +#else + const auto process_id = static_cast(getpid()); +#endif + static std::atomic filename_counter{0}; filename_ = "masked_bulk_copy_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + - ".tsfile"; + "_" + std::to_string(process_id) + "_" + + std::to_string(filename_counter.fetch_add(1)) + ".tsfile"; const std::vector columns{ {"v", INT64, UNCOMPRESSED, PLAIN, ColumnCategory::FIELD}, {"n", INT64, UNCOMPRESSED, PLAIN, ColumnCategory::FIELD}, diff --git a/cpp/test/reader/chunk_reader_resource_test.cc b/cpp/test/reader/chunk_reader_resource_test.cc index 7e0a0af73..159db638c 100644 --- a/cpp/test/reader/chunk_reader_resource_test.cc +++ b/cpp/test/reader/chunk_reader_resource_test.cc @@ -41,6 +41,12 @@ #include "writer/tsfile_table_writer.h" #ifdef ENABLE_THREADS #include "common/thread_pool.h" + +#ifdef _WIN32 +#include +#else +#include +#endif #endif namespace storage { @@ -180,6 +186,17 @@ class AlignedReaderFailureTest : public ::testing::Test { "_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + + "_" + std::to_string([] { +#ifdef _WIN32 + return static_cast(_getpid()); +#else + return static_cast(getpid()); +#endif + }()) + + "_" + std::to_string([] { + static std::atomic counter{0}; + return counter.fetch_add(1); + }()) + ".tsfile"; WriteFile file; int flags = O_WRONLY | O_CREAT | O_TRUNC; diff --git a/cpp/test/reader/table_field_filter_test.cc b/cpp/test/reader/table_field_filter_test.cc index 62b495a83..a7c9aebc0 100644 --- a/cpp/test/reader/table_field_filter_test.cc +++ b/cpp/test/reader/table_field_filter_test.cc @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -36,6 +37,12 @@ #include "reader/table_query_executor.h" #include "writer/tsfile_table_writer.h" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace { using namespace common; using namespace storage; @@ -164,11 +171,19 @@ class TableFieldFilterTest saved_ = g_config_value_; g_config_value_.page_writer_max_point_num_ = 3; g_config_value_.parallel_read_enabled_ = std::get<0>(GetParam()); + // Parallel CTest processes can seed from the same clock tick. +#ifdef _WIN32 + const auto process_id = static_cast(_getpid()); +#else + const auto process_id = static_cast(getpid()); +#endif + static std::atomic filename_counter{0}; filename_ = "table_field_filter_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + - ".tsfile"; + "_" + std::to_string(process_id) + "_" + + std::to_string(filename_counter.fetch_add(1)) + ".tsfile"; WriteFile file; int flags = O_WRONLY | O_CREAT | O_TRUNC; #ifdef _WIN32 diff --git a/cpp/test/reader/table_read_failure_test.cc b/cpp/test/reader/table_read_failure_test.cc index 9e8076612..99d02669b 100644 --- a/cpp/test/reader/table_read_failure_test.cc +++ b/cpp/test/reader/table_read_failure_test.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -42,6 +43,12 @@ #include "utils/injection.h" #include "writer/tsfile_table_writer.h" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace { class InjectionGuard { @@ -106,11 +113,19 @@ class TableReadFailureTest storage::libtsfile_init(); saved_index_degree_ = common::g_config_value_.max_degree_of_index_node_; ASSERT_EQ(storage::set_max_degree_of_index_node(2), common::E_OK); + // Parallel CTest processes can seed from the same clock tick. +#ifdef _WIN32 + const auto process_id = static_cast(_getpid()); +#else + const auto process_id = static_cast(getpid()); +#endif + static std::atomic filename_counter{0}; filename_ = "table_read_failure_" + std::to_string( std::chrono::steady_clock::now().time_since_epoch().count()) + - ".tsfile"; + "_" + std::to_string(process_id) + "_" + + std::to_string(filename_counter.fetch_add(1)) + ".tsfile"; storage::WriteFile file; int flags = O_WRONLY | O_CREAT | O_TRUNC; #ifdef _WIN32 diff --git a/cpp/test/reader/timeseries_schema_codec_test.cc b/cpp/test/reader/timeseries_schema_codec_test.cc index cebb51541..613dda28a 100644 --- a/cpp/test/reader/timeseries_schema_codec_test.cc +++ b/cpp/test/reader/timeseries_schema_codec_test.cc @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -31,6 +32,12 @@ #include "reader/tsfile_reader.h" #include "writer/tsfile_writer.h" +#ifdef _WIN32 +#include +#else +#include +#endif + namespace storage { // get_timeseries_schema() reports the encoding and the compressor of every @@ -77,6 +84,16 @@ class TimeseriesSchemaCodecTest : public ::testing::Test { for (int i = 0; i < length; ++i) { s += chars[static_cast(dis(gen))]; } + // CTest runs cases in parallel processes; two can seed from the same + // clock tick and then collide on the file name. +#ifdef _WIN32 + const auto process_id = static_cast(_getpid()); +#else + const auto process_id = static_cast(getpid()); +#endif + static std::atomic filename_counter{0}; + s += "_" + std::to_string(process_id) + "_" + + std::to_string(filename_counter.fetch_add(1)); return s; } From 3f8078b253436e44e7b89b5c7ec1fcbce99ef829 Mon Sep 17 00:00:00 2001 From: ColinLee Date: Sat, 14 Nov 2026 15:35:53 +0800 Subject: [PATCH 2/2] test(cpp): keep the pid includes outside ENABLE_THREADS 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. --- cpp/test/reader/aligned_chunk_reader_bulk_test.cc | 12 ++++++------ cpp/test/reader/chunk_reader_resource_test.cc | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cpp/test/reader/aligned_chunk_reader_bulk_test.cc b/cpp/test/reader/aligned_chunk_reader_bulk_test.cc index d3efd8796..c5c5d2291 100644 --- a/cpp/test/reader/aligned_chunk_reader_bulk_test.cc +++ b/cpp/test/reader/aligned_chunk_reader_bulk_test.cc @@ -29,6 +29,12 @@ #include #include +#ifdef _WIN32 +#include +#else +#include +#endif + #include "common/allocator/alloc_base.h" #include "common/config/config.h" #include "common/tablet.h" @@ -42,12 +48,6 @@ #include "writer/tsfile_table_writer.h" #ifdef ENABLE_THREADS #include "common/thread_pool.h" - -#ifdef _WIN32 -#include -#else -#include -#endif #endif using namespace common; diff --git a/cpp/test/reader/chunk_reader_resource_test.cc b/cpp/test/reader/chunk_reader_resource_test.cc index 159db638c..3da4d840d 100644 --- a/cpp/test/reader/chunk_reader_resource_test.cc +++ b/cpp/test/reader/chunk_reader_resource_test.cc @@ -29,6 +29,12 @@ #include #include +#ifdef _WIN32 +#include +#else +#include +#endif + #include "common/allocator/alloc_base.h" #include "common/config/config.h" #include "common/tablet.h" @@ -41,12 +47,6 @@ #include "writer/tsfile_table_writer.h" #ifdef ENABLE_THREADS #include "common/thread_pool.h" - -#ifdef _WIN32 -#include -#else -#include -#endif #endif namespace storage {