diff --git a/cpp/test/reader/aligned_chunk_reader_bulk_test.cc b/cpp/test/reader/aligned_chunk_reader_bulk_test.cc index 0be62def8..c5c5d2291 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 @@ -28,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" @@ -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..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" @@ -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; }