Skip to content

Move topic tests 2 #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
"name": "release-test-gcc",
"inherits": ["release-base", "gcc-toolchain", "test"],
"displayName": "Default Release Test Config (GCC)"
},
{
"name": "debug-clang",
"inherits": ["debug-base", "clang-toolchain"],
"displayName": "Default Debug Config (Clang)"
},
{
"name": "debug-gcc",
"inherits": ["debug-base", "gcc-toolchain"],
"displayName": "Default Debug Config (GCC)"
},
{
"name": "debug-test-clang",
"inherits": ["debug-base", "clang-toolchain", "test"],
"displayName": "Default Debug Test Config (Clang)"
},
{
"name": "debug-test-gcc",
"inherits": ["debug-base", "gcc-toolchain", "test"],
"displayName": "Default Debug Test Config (GCC)"
}
],
"buildPresets": [
Expand Down
32 changes: 27 additions & 5 deletions cmake/testing.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
enable_testing()

find_package(GTest REQUIRED)
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 1.15.2
FIND_PACKAGE_ARGS NAMES GTest
)

FetchContent_MakeAvailable(googletest)

include(GoogleTest)

function(add_ydb_test)
set(opts GTEST)
set(oneval_args NAME WORKING_DIRECTORY OUTPUT_DIRECTORY)
set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS TEST_ARG)
set(multival_args INCLUDE_DIRS SOURCES LINK_LIBRARIES LABELS TEST_ARG ENV)
cmake_parse_arguments(YDB_TEST
"${opts}"
"${oneval_args}"
Expand Down Expand Up @@ -49,16 +59,24 @@ function(add_ydb_test)
endif()

if (YDB_TEST_GTEST)
set(env_vars "")
foreach(env_var ${YDB_TEST_ENV})
list(APPEND env_vars "ENVIRONMENT")
list(APPEND env_vars ${env_var})
endforeach()

gtest_discover_tests(${YDB_TEST_NAME}
EXTRA_ARGS ${YDB_TEST_TEST_ARG}
WORKING_DIRECTORY ${YDB_TEST_WORKING_DIRECTORY}
PROPERTIES LABELS ${YDB_TEST_LABELS}
PROPERTIES PROCESSORS 1
PROPERTIES TIMEOUT 600
PROPERTIES
LABELS ${YDB_TEST_LABELS}
ENVIRONMENT "YDB_TEST_ROOT=sdk_tests"
${env_vars}
)

target_link_libraries(${YDB_TEST_NAME} PRIVATE
GTest::gtest_main
GTest::gmock_main
)
else()
add_test(NAME ${YDB_TEST_NAME}
Expand All @@ -79,6 +97,10 @@ function(add_ydb_test)
set_tests_properties(${YDB_TEST_NAME} PROPERTIES LABELS ${YDB_TEST_LABELS})
set_tests_properties(${YDB_TEST_NAME} PROPERTIES PROCESSORS 1)
set_tests_properties(${YDB_TEST_NAME} PROPERTIES TIMEOUT 600)
set_tests_properties(${YDB_TEST_NAME} PROPERTIES ENVIRONMENT "YDB_TEST_ROOT=sdk_tests")
if (YDB_TEST_ENV)
set_tests_properties(${YDB_TEST_NAME} PROPERTIES ENVIRONMENT ${YDB_TEST_ENV})
endif()
endif()

vcs_info(${YDB_TEST_NAME})
Expand Down
1 change: 0 additions & 1 deletion include/ydb-cpp-sdk/library/retry/retry_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <functional>
#include <limits>
#include <optional>
#include <memory>

//! Retry policy.
Expand Down
105 changes: 0 additions & 105 deletions src/client/topic/ut/describe_topic_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#include "ut_utils/topic_sdk_test_setup.h"

#include <format>
#include <src/library/persqueue/topic_parser_public/topic_parser.h>
#include <src/api/protos/persqueue_error_codes_v1.pb.h>
#include <ydb-cpp-sdk/client/topic/client.h>
#include <src/client/persqueue_public/persqueue.h>
#include <src/client/topic/common/log_lazy.h>
#include <src/client/topic/impl/common.h>

#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/testing/unittest/tests_data.h>
#include <library/cpp/threading/future/future.h>
#include <library/cpp/threading/future/async.h>

namespace NYdb::NTopic::NTests {

Expand Down Expand Up @@ -258,106 +249,10 @@ namespace NYdb::NTopic::NTests {
}
}

Y_UNIT_TEST(Basic) {
TTopicSdkTestSetup setup(TEST_CASE_NAME);
TTopicClient client = setup.MakeClient();

DescribeTopic(setup, client, false, false, false, false);
DescribeConsumer(setup, client, false, false, false, false);
DescribePartition(setup, client, false, false, false, false);
}

Y_UNIT_TEST(Statistics) {
// TODO(abcdef): temporarily deleted
return;

TTopicSdkTestSetup setup(TEST_CASE_NAME);
TTopicClient client = setup.MakeClient();

// Get empty description
DescribeTopic(setup, client, true, false, false, false);
DescribeConsumer(setup, client, true, false, false, false);
DescribePartition(setup, client, true, false, false, false);

const size_t messagesCount = 1;

// Write a message
{
auto writeSettings = TWriteSessionSettings().Path(TEST_TOPIC).MessageGroupId(TEST_MESSAGE_GROUP_ID).Codec(ECodec::RAW);
auto writeSession = client.CreateSimpleBlockingWriteSession(writeSettings);
std::string message(32_MB, 'x');

for(size_t i = 0; i < messagesCount; ++i) {
UNIT_ASSERT(writeSession->Write(message, {}, TInstant::Now() - TDuration::Seconds(100)));
}
writeSession->Close();
}

// Read a message
{
auto readSettings = TReadSessionSettings().ConsumerName(TEST_CONSUMER).AppendTopics(TEST_TOPIC);
auto readSession = client.CreateReadSession(readSettings);

// Event 1: start partition session
{
std::optional<TReadSessionEvent::TEvent> event = readSession->GetEvent(true);
UNIT_ASSERT(event);
auto startPartitionSession = std::get_if<TReadSessionEvent::TStartPartitionSessionEvent>(&event.value());
UNIT_ASSERT_C(startPartitionSession, DebugString(*event));

startPartitionSession->Confirm();
}

// Event 2: data received
{
std::optional<TReadSessionEvent::TEvent> event = readSession->GetEvent(true);
UNIT_ASSERT(event);
auto dataReceived = std::get_if<TReadSessionEvent::TDataReceivedEvent>(&event.value());
UNIT_ASSERT_C(dataReceived, DebugString(*event));

dataReceived->Commit();
}

// Event 3: commit acknowledgement
{
std::optional<TReadSessionEvent::TEvent> event = readSession->GetEvent(true);
UNIT_ASSERT(event);
auto commitOffsetAck = std::get_if<TReadSessionEvent::TCommitOffsetAcknowledgementEvent>(&event.value());

UNIT_ASSERT_C(commitOffsetAck, DebugString(*event));

UNIT_ASSERT_VALUES_EQUAL(commitOffsetAck->GetCommittedOffset(), messagesCount);
}
}

// Additional write
{
auto writeSettings = TWriteSessionSettings().Path(TEST_TOPIC).MessageGroupId(TEST_MESSAGE_GROUP_ID).Codec(ECodec::RAW);
auto writeSession = client.CreateSimpleBlockingWriteSession(writeSettings);
std::string message(32, 'x');

for(size_t i = 0; i < messagesCount; ++i) {
UNIT_ASSERT(writeSession->Write(message));
}
writeSession->Close();
}
Sleep(TDuration::Seconds(3));

// Get non-empty description

DescribeTopic(setup, client, true, true, false, false);
DescribeConsumer(setup, client, true, true, false, false);
DescribePartition(setup, client, true, true, false, false);
}

Y_UNIT_TEST(Location) {
TTopicSdkTestSetup setup(TEST_CASE_NAME);
TTopicClient client = setup.MakeClient();

DescribeTopic(setup, client, false, false, true, false);
DescribeConsumer(setup, client, false, false, true, false);
DescribePartition(setup, client, false, false, true, false);

// Describe with KillTablets
DescribeTopic(setup, client, false, false, true, true);
DescribeConsumer(setup, client, false, false, true, true);
Expand Down
Loading
Loading