diff options
| author | Bulat <[email protected]> | 2025-06-17 21:42:03 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-17 21:42:03 +0300 |
| commit | 71f3186a075dd5aa34e2840ef29fc3958a89d2fa (patch) | |
| tree | 0a44b99577d0998e1d5000c2767f74c7cdc347b7 | |
| parent | 987e6f4b279799053daaa2af4286057cf2c039b4 (diff) | |
Fixed topic tests run in ydb-cpp-sdk repo (#19778)
7 files changed, 87 insertions, 52 deletions
diff --git a/ydb/public/sdk/cpp/tests/integration/topic/basic_usage.cpp b/ydb/public/sdk/cpp/tests/integration/topic/basic_usage.cpp index 1a8602e8123..2ccf89df946 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/basic_usage.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/basic_usage.cpp @@ -10,10 +10,9 @@ #include <util/generic/overloaded.h> #include <util/stream/zlib.h> -#include <future> - +#include <gtest/gtest.h> -static const bool EnableDirectRead = !std::string{std::getenv("PQ_EXPERIMENTAL_DIRECT_READ") ? std::getenv("PQ_EXPERIMENTAL_DIRECT_READ") : ""}.empty(); +#include <future> namespace NYdb::inline Dev::NPersQueue::NTests { @@ -174,7 +173,7 @@ TIntrusivePtr<TManagedExecutor> CreateSyncManagedExecutor() class BasicUsage : public TTopicTestFixture {}; -TEST_F(BasicUsage, ConnectToYDB) { +TEST_F(BasicUsage, TEST_NAME(ConnectToYDB)) { auto cfg = NYdb::TDriverConfig() .SetEndpoint("invalid:2136") .SetDatabase("/Invalid") @@ -213,7 +212,7 @@ TEST_F(BasicUsage, ConnectToYDB) { } } -TEST_F(BasicUsage, WriteRead) { +TEST_F(BasicUsage, TEST_NAME(WriteRead)) { auto driver = MakeDriver(); TTopicClient client(driver); @@ -245,7 +244,7 @@ TEST_F(BasicUsage, WriteRead) { { auto readSettings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) ; @@ -270,7 +269,7 @@ TEST_F(BasicUsage, WriteRead) { } } -TEST_F(BasicUsage, MaxByteSizeEqualZero) { +TEST_F(BasicUsage, TEST_NAME(MaxByteSizeEqualZero)) { auto driver = MakeDriver(); TTopicClient client(driver); @@ -283,7 +282,7 @@ TEST_F(BasicUsage, MaxByteSizeEqualZero) { writeSession->Close(); auto readSettings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) ; @@ -305,7 +304,7 @@ TEST_F(BasicUsage, MaxByteSizeEqualZero) { dataReceived.Commit(); } -TEST_F(BasicUsage, WriteAndReadSomeMessagesWithSyncCompression) { +TEST_F(BasicUsage, TEST_NAME(WriteAndReadSomeMessagesWithSyncCompression)) { auto driver = MakeDriver(); IExecutor::TPtr executor = new TSyncExecutor(); @@ -353,7 +352,7 @@ TEST_F(BasicUsage, WriteAndReadSomeMessagesWithSyncCompression) { // Create read session. TReadSessionSettings readSettings; readSettings - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .MaxMemoryUsageBytes(1_MB) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) @@ -387,11 +386,11 @@ TEST_F(BasicUsage, WriteAndReadSomeMessagesWithSyncCompression) { ReadSession->Close(TDuration::MilliSeconds(10)); check.store(0); - auto status = topicClient.CommitOffset(GetTopicPath(), 0, "test-consumer", 50); + auto status = topicClient.CommitOffset(GetTopicPath(), 0, GetConsumerName(), 50); ASSERT_TRUE(status.GetValueSync().IsSuccess()); auto describeConsumerSettings = TDescribeConsumerSettings().IncludeStats(true); - auto result = topicClient.DescribeConsumer(GetTopicPath(), "test-consumer", describeConsumerSettings).GetValueSync(); + auto result = topicClient.DescribeConsumer(GetTopicPath(), GetConsumerName(), describeConsumerSettings).GetValueSync(); ASSERT_TRUE(result.IsSuccess()); auto description = result.GetConsumerDescription(); @@ -401,7 +400,7 @@ TEST_F(BasicUsage, WriteAndReadSomeMessagesWithSyncCompression) { ASSERT_EQ(stats->GetCommittedOffset(), 50u); } -TEST_F(BasicUsage, SessionNotDestroyedWhileCompressionInFlight) { +TEST_F(BasicUsage, TEST_NAME(SessionNotDestroyedWhileCompressionInFlight)) { auto driver = MakeDriver(); // controlled executor @@ -425,7 +424,7 @@ TEST_F(BasicUsage, SessionNotDestroyedWhileCompressionInFlight) { // Create read session. TReadSessionSettings readSettings; readSettings - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .MaxMemoryUsageBytes(1_MB) .AppendTopics(GetTopicPath()) .DecompressionExecutor(stepByStepExecutor) @@ -511,7 +510,7 @@ TEST_F(BasicUsage, SessionNotDestroyedWhileCompressionInFlight) { std::cerr << ">>> TEST: gracefully closed" << std::endl; } -TEST_F(BasicUsage, SessionNotDestroyedWhileUserEventHandlingInFlight) { +TEST_F(BasicUsage, TEST_NAME(SessionNotDestroyedWhileUserEventHandlingInFlight)) { auto driver = MakeDriver(); // controlled executor @@ -542,7 +541,7 @@ TEST_F(BasicUsage, SessionNotDestroyedWhileUserEventHandlingInFlight) { // Create read session. auto readSettings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .MaxMemoryUsageBytes(1_MB) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) @@ -643,7 +642,7 @@ TEST_F(BasicUsage, SessionNotDestroyedWhileUserEventHandlingInFlight) { std::cerr << ">>> TEST: gracefully closed" << std::endl; } -TEST_F(BasicUsage, ReadSessionCorrectClose) { +TEST_F(BasicUsage, TEST_NAME(ReadSessionCorrectClose)) { auto driver = MakeDriver(); NPersQueue::TWriteSessionSettings writeSettings; @@ -672,7 +671,7 @@ TEST_F(BasicUsage, ReadSessionCorrectClose) { // Create read session. NYdb::NTopic::TReadSessionSettings readSettings; readSettings - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .MaxMemoryUsageBytes(1_MB) .Decompress(false) .RetryPolicy(NYdb::NTopic::IRetryPolicy::GetNoRetryPolicy()) @@ -700,7 +699,7 @@ TEST_F(BasicUsage, ReadSessionCorrectClose) { std::this_thread::sleep_for(std::chrono::seconds(5)); } -TEST_F(BasicUsage, ConfirmPartitionSessionWithCommitOffset) { +TEST_F(BasicUsage, TEST_NAME(ConfirmPartitionSessionWithCommitOffset)) { // TStartPartitionSessionEvent::Confirm(readOffset, commitOffset) should work, // if commitOffset passed to Confirm is greater than the offset committed previously by the consumer. // https://st.yandex-team.ru/KIKIMR-23015 @@ -723,7 +722,7 @@ TEST_F(BasicUsage, ConfirmPartitionSessionWithCommitOffset) { { // Read messages: auto settings = NTopic::TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) ; @@ -760,7 +759,7 @@ TEST_F(BasicUsage, ConfirmPartitionSessionWithCommitOffset) { } } -TEST_F(BasicUsage, TWriteSession_WriteEncoded) { +TEST_F(BasicUsage, TEST_NAME(TWriteSession_WriteEncoded)) { // This test was adapted from ydb_persqueue tests. // It writes 4 messages: 2 with default codec, 1 with explicitly set GZIP codec, 1 with RAW codec. // The last message MUST be sent in a separate WriteRequest, as it has a codec field applied for all messages in the request. @@ -831,7 +830,7 @@ TEST_F(BasicUsage, TWriteSession_WriteEncoded) { ASSERT_EQ(tokens, 2u); auto readSettings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) ; @@ -886,7 +885,7 @@ namespace { class TSettingsValidation : public TTopicTestFixture {}; -TEST_F(TSettingsValidation, TestDifferentDedupParams) { +TEST_F(TSettingsValidation, TEST_NAME(TestDifferentDedupParams)) { char* ydbVersion = std::getenv("YDB_VERSION"); if (ydbVersion != nullptr && std::string(ydbVersion) != "trunk" && std::string(ydbVersion) < "24.3") { GTEST_SKIP() << "Skipping test for YDB version " << ydbVersion; @@ -1003,13 +1002,13 @@ TEST_F(TSettingsValidation, TestDifferentDedupParams) { runTest({}, "msgGroup", {}, false, EExpectedTestResult::SUCCESS); } -TEST_F(TSettingsValidation, ValidateSettingsFailOnStart) { +TEST_F(TSettingsValidation, TEST_NAME(ValidateSettingsFailOnStart)) { auto driver = MakeDriver(); TTopicClient client(driver); auto readSettings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .MaxMemoryUsageBytes(0) .AppendTopics(GetTopicPath()) // .DirectRead(EnableDirectRead) diff --git a/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp b/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp index 6f587b46a19..1e5d5dcb4dc 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp @@ -56,7 +56,7 @@ protected: settings.IncludeLocation(requireLocation); { - auto result = client.DescribeConsumer(GetTopicPath(), "test-consumer", settings).GetValueSync(); + auto result = client.DescribeConsumer(GetTopicPath(), GetConsumerName(), settings).GetValueSync(); EXPECT_TRUE(result.IsSuccess()) << result.GetIssues().ToString(); const auto& description = result.GetConsumerDescription(); @@ -149,7 +149,7 @@ protected: } }; -TEST_F(Describe, Basic) { +TEST_F(Describe, TEST_NAME(Basic)) { TTopicClient client(MakeDriver()); DescribeTopic(client, false, false, false); @@ -157,7 +157,7 @@ TEST_F(Describe, Basic) { DescribePartition(client, false, false, false); } -TEST_F(Describe, Statistics) { +TEST_F(Describe, TEST_NAME(Statistics)) { // TODO(abcdef): temporarily deleted GTEST_SKIP() << "temporarily deleted"; @@ -184,7 +184,7 @@ TEST_F(Describe, Statistics) { // Read a message { - auto readSettings = TReadSessionSettings().ConsumerName("test-consumer").AppendTopics(GetTopicPath()); + auto readSettings = TReadSessionSettings().ConsumerName(GetConsumerName()).AppendTopics(GetTopicPath()); auto readSession = client.CreateReadSession(readSettings); // Event 1: start partition session @@ -239,7 +239,7 @@ TEST_F(Describe, Statistics) { DescribePartition(client, true, true, false); } -TEST_F(Describe, Location) { +TEST_F(Describe, TEST_NAME(Location)) { TTopicClient client(MakeDriver()); DescribeTopic(client, false, false, true); diff --git a/ydb/public/sdk/cpp/tests/integration/topic/direct_read.cpp b/ydb/public/sdk/cpp/tests/integration/topic/direct_read.cpp index 4ce19aa887a..624bbc0b348 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/direct_read.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/direct_read.cpp @@ -882,7 +882,7 @@ TEST_F(DirectReadWithClient, OneMessage) { // Read the message: auto settings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) // .DirectRead(true) ; @@ -929,7 +929,7 @@ TEST_F(DirectReadWithClient, ManyMessages) { constexpr std::size_t partitionCount = 2; std::size_t messageCount = 100; std::size_t totalMessageCount = partitionCount * messageCount; - CreateTopic(GetTopicPath(), "test-consumer", partitionCount); + CreateTopic(GetTopicPath(), GetConsumerName(), partitionCount); TTopicClient client{MakeDriver()}; std::string message(950_KB, 'x'); @@ -966,7 +966,7 @@ TEST_F(DirectReadWithClient, ManyMessages) { std::size_t gotMessages = 0; std::array<std::size_t, partitionCount> committedOffset{}; auto settings = TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()) .MaxMemoryUsageBytes(1_MB) // .DirectRead(GetEnv("DIRECT", "0") == "1") @@ -1064,6 +1064,9 @@ TEST_F(DirectReadWithControlSession, Init) { } TEST_F(DirectReadWithControlSession, StopPartitionSessionGracefully) { +#ifdef __GNUC__ + GTEST_SKIP() << "Skip for gcc"; +#endif auto const startPartitionSessionRequest = TStartPartitionSessionRequest{ .PartitionId = 1, .PartitionSessionId = 2, diff --git a/ydb/public/sdk/cpp/tests/integration/topic/local_partition.cpp b/ydb/public/sdk/cpp/tests/integration/topic/local_partition.cpp index 0bd50786e90..3b7d9aa4f27 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/local_partition.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/local_partition.cpp @@ -173,7 +173,7 @@ protected: TReadSessionSettings CreateReadSessionSettings() { return TReadSessionSettings() - .ConsumerName("test-consumer") + .ConsumerName(GetConsumerName()) .AppendTopics(GetTopicPath()); } @@ -309,7 +309,7 @@ private: std::chrono::milliseconds Delay = {}; }; -TEST_F(LocalPartition, Basic) { +TEST_F(LocalPartition, TEST_NAME(Basic)) { TMockDiscoveryService discovery; discovery.SetGoodEndpoints(*this); TDriver driver(CreateConfig(discovery.GetDiscoveryAddr())); @@ -319,7 +319,7 @@ TEST_F(LocalPartition, Basic) { ReadMessage(client); } -TEST_F(LocalPartition, DescribeBadPartition) { +TEST_F(LocalPartition, TEST_NAME(DescribeBadPartition)) { TMockDiscoveryService discovery; discovery.SetGoodEndpoints(*this); @@ -354,7 +354,7 @@ TEST_F(LocalPartition, DescribeBadPartition) { writeSession->Close(); } -TEST_F(LocalPartition, DiscoveryServiceBadPort) { +TEST_F(LocalPartition, TEST_NAME(DiscoveryServiceBadPort)) { TMockDiscoveryService discovery; discovery.SetEndpoints(9999, 2, 0); @@ -382,7 +382,7 @@ TEST_F(LocalPartition, DiscoveryServiceBadPort) { writeSession->Close(); } -TEST_F(LocalPartition, DiscoveryServiceBadNodeId) { +TEST_F(LocalPartition, TEST_NAME(DiscoveryServiceBadNodeId)) { TMockDiscoveryService discovery; discovery.SetEndpoints(9999, GetNodeIds().size(), GetPort()); @@ -410,7 +410,7 @@ TEST_F(LocalPartition, DiscoveryServiceBadNodeId) { writeSession->Close(); } -TEST_F(LocalPartition, DescribeHang) { +TEST_F(LocalPartition, TEST_NAME(DescribeHang)) { TMockDiscoveryService discovery; discovery.SetGoodEndpoints(*this); @@ -430,7 +430,7 @@ TEST_F(LocalPartition, DescribeHang) { writeSession->Close(); } -TEST_F(LocalPartition, DiscoveryHang) { +TEST_F(LocalPartition, TEST_NAME(DiscoveryHang)) { TMockDiscoveryService discovery; discovery.SetGoodEndpoints(*this); discovery.SetDelay(std::chrono::days(1)); @@ -443,7 +443,7 @@ TEST_F(LocalPartition, DiscoveryHang) { writeSession->Close(); } -TEST_F(LocalPartition, WithoutPartition) { +TEST_F(LocalPartition, TEST_NAME(WithoutPartition)) { // Direct write without partition: happy way. TMockDiscoveryService discovery; discovery.SetGoodEndpoints(*this); @@ -485,7 +485,7 @@ TEST_F(LocalPartition, WithoutPartition) { ASSERT_TRUE(expected.Matches(events)); } -TEST_F(LocalPartition, WithoutPartitionDeadNode) { +TEST_F(LocalPartition, TEST_NAME(WithoutPartitionDeadNode)) { // This test emulates a situation, when InitResponse directs us to an inaccessible node. TMockDiscoveryService discovery; discovery.SetEndpoints(GetNodeIds()[0], 1, 0); diff --git a/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.cpp b/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.cpp index bec648a7cfa..ed6e9c3ee89 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.cpp @@ -6,24 +6,32 @@ namespace NYdb::inline Dev::NTopic::NTests { +const bool EnableDirectRead = !std::string{std::getenv("PQ_EXPERIMENTAL_DIRECT_READ") ? std::getenv("PQ_EXPERIMENTAL_DIRECT_READ") : ""}.empty(); + void TTopicTestFixture::SetUp() { + char* ydbVersion = std::getenv("YDB_VERSION"); + + if (EnableDirectRead && ydbVersion != nullptr && std::string(ydbVersion) != "trunk" && std::string(ydbVersion) <= "25.1") { + GTEST_SKIP() << "Skipping test for YDB version " << ydbVersion; + } + TTopicClient client(MakeDriver()); const testing::TestInfo* const testInfo = testing::UnitTest::GetInstance()->current_test_info(); std::filesystem::path execPath(std::string{GetExecPath()}); - std::stringstream builder; - builder << std::getenv("YDB_TEST_ROOT") << "/" << execPath.filename().string() << "/" << testInfo->test_suite_name() << "_" << testInfo->name(); - TopicPath_ = builder.str(); + std::stringstream topicBuilder; + topicBuilder << std::getenv("YDB_TEST_ROOT") << "/" << testInfo->test_suite_name() << "-" << testInfo->name(); + TopicPath_ = topicBuilder.str(); + + std::stringstream consumerBuilder; + consumerBuilder << testInfo->test_suite_name() << "-" << testInfo->name() << "-consumer"; + ConsumerName_ = consumerBuilder.str(); client.DropTopic(TopicPath_).GetValueSync(); CreateTopic(TopicPath_); } -void TTopicTestFixture::TearDown() { - DropTopic(GetTopicPath()); -} - void TTopicTestFixture::CreateTopic(const std::string& path, const std::string& consumer, size_t partitionCount, std::optional<size_t> maxPartitionCount) { TTopicClient client(MakeDriver()); @@ -47,10 +55,18 @@ void TTopicTestFixture::CreateTopic(const std::string& path, const std::string& Y_ENSURE(status.IsSuccess(), status); } +void TTopicTestFixture::CreateTopic(const std::string& path, size_t partitionCount, std::optional<size_t> maxPartitionCount) { + CreateTopic(path, GetConsumerName(), partitionCount, maxPartitionCount); +} + std::string TTopicTestFixture::GetTopicPath() { return TopicPath_; } +std::string TTopicTestFixture::GetConsumerName() { + return ConsumerName_; +} + void TTopicTestFixture::DropTopic(const std::string& path) { TTopicClient client(MakeDriver()); auto status = client.DropTopic(path).GetValueSync(); diff --git a/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.h b/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.h index 71e59189dbd..4796b33208f 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.h +++ b/ydb/public/sdk/cpp/tests/integration/topic/setup/fixture.h @@ -6,15 +6,20 @@ namespace NYdb::inline Dev::NTopic::NTests { +extern const bool EnableDirectRead; + class TTopicTestFixture : public ::testing::Test { public: - void SetUp() override; - void TearDown() override; + void SetUp() override; + + void CreateTopic(const std::string& path, const std::string& consumer, std::size_t partitionCount = 1, + std::optional<std::size_t> maxPartitionCount = std::nullopt); - void CreateTopic(const std::string& path, const std::string& consumer = "test-consumer", std::size_t partitionCount = 1, + void CreateTopic(const std::string& path, std::size_t partitionCount = 1, std::optional<std::size_t> maxPartitionCount = std::nullopt); std::string GetTopicPath(); + std::string GetConsumerName(); void DropTopic(const std::string& path); @@ -24,8 +29,16 @@ public: std::uint16_t GetPort() const; std::vector<std::uint32_t> GetNodeIds() const; + private: std::string TopicPath_; + std::string ConsumerName_; }; } + +#ifdef PQ_EXPERIMENTAL_DIRECT_READ + #define TEST_NAME(name) DirectRead_##name +#else + #define TEST_NAME(name) name +#endif diff --git a/ydb/public/sdk/cpp/tests/integration/topic/with_direct_read/ya.make b/ydb/public/sdk/cpp/tests/integration/topic/with_direct_read/ya.make index 34367f57b60..1e974f9606a 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/with_direct_read/ya.make +++ b/ydb/public/sdk/cpp/tests/integration/topic/with_direct_read/ya.make @@ -25,6 +25,10 @@ YQL_LAST_ABI_VERSION() ENV(PQ_EXPERIMENTAL_DIRECT_READ="1") +CFLAGS( + -DPQ_EXPERIMENTAL_DIRECT_READ=1 +) + SRCS( ../basic_usage.cpp ../describe_topic.cpp |
