Skip to content
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

TEL-26, TEL-29 [9.x]: Add unit tests and MTR tests for Percona Telemetry Component #5473

Merged
merged 14 commits into from
Nov 6, 2024

Conversation

inikep
Copy link
Collaborator

@inikep inikep commented Nov 6, 2024

kamil-holubicki and others added 14 commits September 17, 2024 13:44
Fix the following issue:
```
273: /data/mysql-server/8.x/router/tests/helpers/process_manager.cc:732: Failure
273: Expected equality of these values:
273:   expected_exit_status
273:     Which is: Exit(0)
273:   result
273:     Which is: Exit(128)
273: Process 1325111 exited with Exit(128)
273: /data/mysql-server/8.x/router/tests/helpers/process_manager.cc:669: Failure
273: Failed
273: # Process: (pid=1325111)
273: /data/mysql-server/8.x-deb-gcc13-rocks/runtime_output_directory/mysqld --no-defaults --lc-messages-dir=/data/mysql-server/8.x-deb-gcc13-rocks/share --datadir=/tmp/mysqld-debug-0Pfsrx --plugin_dir=/data/mysql-server/8.x-deb-gcc13-rocks/plugin_output_directory --log-error=/tmp/mysqld-debug-0Pfsrx/mysqld-0.err --port=11010 --socket=/tmp/mysqld-debug-0Pfsrx/mysql.sock --mysqlx-port=11011 --mysqlx-socket=/tmp/mysqld-debug-0Pfsrx/mysqlx.sock --secure-file-priv=NULL --innodb_redo_log_capacity=8M --innodb_autoextend_increment=1 --innodb_buffer_pool_size=5M --innodb_use_native_aio=0 --gtid_mode=ON --enforce_gtid_consistency=ON --relay-log=relay-log
273:
273: ## Console output:
273:
273: /data/mysql-server/8.x-deb-gcc13-rocks/runtime_output_directory/mysqld could not be executed: No such file or directory (errno 2)
273:
273: ## Log content:
273:
273: <THIS ERROR COMES FROM TEST FRAMEWORK'S get_file_output(), IT IS NOT PART OF PROCESS OUTPUT: Could not open file '/tmp/mysqld-debug-0Pfsrx/mysqld-0.err' for reading: basic_ios::clear: iostream error>
273:
273: /data/mysql-server/8.x/router/tests/helpers/process_manager.cc:732: Failure
273: Expected equality of these values:
273:   expected_exit_status
273:     Which is: Exit(0)
273:   result
273:     Which is: Exit(128)
273: Process 1325111 exited with Exit(128)
```
PS-9328 [8.4]: Revert fixes for unsupported gcc and clang versions
PS-9388 [8.4]: Fix "routertest_integration_routing*"
TEL-26, TEL-29: Add unit tests and MTR tests for Percona Telemetry Component
Post push fix.

1. Added missing Boost dependency. It caused unit tests build to fail
if no Boost was installed in system.
2. Removed unnecessary component dependency. It caused unit tests
build to fail if configured with WITH_PERCONA_TELEMETRY=NO
…-fix-8.4

TEL-26: Percona Telemetry Component unit tests added
…from kamil-holubicki/TEL-26-post-push-fix-8.4)
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/4)

#include "components/percona_telemetry/logger.h"
#undef private

using ::testing::_;
Copy link

Choose a reason for hiding this comment

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

⚠️ bugprone-reserved-identifier ⚠️
declaration uses identifier _, which is reserved in the global namespace; cannot be fixed automatically


class MockDataProvider : public DataProvider {
public:
MockDataProvider()
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-pro-type-member-init ⚠️
constructor does not initialize these fields: gmock04_do_query_41


class DataProviderTest : public ::testing::Test {
protected:
virtual void SetUp() {}
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-explicit-virtual-functions ⚠️
prefer using override or (rarely) final instead of virtual

Suggested change
virtual void SetUp() {}
void SetUp() override {}

class DataProviderTest : public ::testing::Test {
protected:
virtual void SetUp() {}
virtual void TearDown() {}
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-explicit-virtual-functions ⚠️
prefer using override or (rarely) final instead of virtual

Suggested change
virtual void TearDown() {}
void TearDown() override {}

virtual void TearDown() {}
};

TEST_F(DataProviderTest, Sanity_test) { EXPECT_EQ(1, 1); }
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "Sanity_test" according to Googletest FAQ


TEST_F(DataProviderTest, Sanity_test) { EXPECT_EQ(1, 1); }

TEST_F(DataProviderTest, get_database_instance_id_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "get_database_instance_id_test" according to Googletest FAQ

TEST_F(DataProviderTest, get_database_instance_id_test) {
MockDataProvider dataProvider;
const std::string expected_id("expected_id");
Row row{expected_id};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{expected_id};
Row row = 0{expected_id};

EXPECT_EQ(dataProvider.get_database_instance_id(), expected_id);
}

TEST_F(DataProviderTest, get_database_instance_id_queries_only_once_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "get_database_instance_id_queries_only_once_test" according to Googletest FAQ

TEST_F(DataProviderTest, get_database_instance_id_queries_only_once_test) {
MockDataProvider dataProvider;
const std::string expected_id("expected_id");
Row row{expected_id};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{expected_id};
Row row = 0{expected_id};

EXPECT_EQ(dataProvider.get_database_instance_id(), expected_id);
}

TEST_F(DataProviderTest, get_database_instance_id_do_query_fails_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "get_database_instance_id_do_query_fails_test" according to Googletest FAQ

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (2/4)

TEST_F(DataProviderTest, get_database_instance_id_do_query_fails_test) {
MockDataProvider dataProvider;
const std::string expected_id("expected_id");
Row row{expected_id};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{expected_id};
Row row = 0{expected_id};

// Helper function for metrics reported as a single value
static void collect_single_value_common(
const std::string &expected_query, const std::string &expected_json_key,
std::function<bool(MockDataProvider *, rapidjson::Document *)> fn,
Copy link

Choose a reason for hiding this comment

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

⚠️ misc-unused-parameters ⚠️
parameter fn is unused

Suggested change
std::function<bool(MockDataProvider *, rapidjson::Document *)> fn,

bool should_cache_result = false) {
MockDataProvider dataProvider;
const std::string expected_val("expected_val");
Row row{expected_val};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{expected_val};
Row row = 0{expected_val};

Comment on lines +134 to +135
const std::string &expected_query, const std::string &expected_json_key,
std::function<bool(MockDataProvider *, rapidjson::Document *)> fn) {
Copy link

Choose a reason for hiding this comment

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

⚠️ misc-unused-parameters ⚠️
parameter fn is unused

Suggested change
const std::string &expected_query, const std::string &expected_json_key,
std::function<bool(MockDataProvider *, rapidjson::Document *)> fn) {
const std::string &expected_query, const std::string &expected_json_key) {

MockDataProvider dataProvider;
std::string Item_A("Item_A");
std::string Item_B("Item_B");
Row row1{Item_A};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row1 is not initialized

Suggested change
Row row1{Item_A};
Row row1 = 0{Item_A};

std::string Item_A("Item_A");
std::string Item_B("Item_B");
Row row1{Item_A};
Row row2{Item_B};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row2 is not initialized

Suggested change
Row row2{Item_B};
Row row2 = 0{Item_B};

EXPECT_FALSE(fn(&dataProvider, &document2));
}

TEST_F(DataProviderTest, collect_db_instance_id_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_db_instance_id_info_test" according to Googletest FAQ

true);
}

TEST_F(DataProviderTest, collect_product_version_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_product_version_info_test" according to Googletest FAQ


TEST_F(DataProviderTest, collect_product_version_info_test) {
MockDataProvider dataProvider;
Row row{"1.2.3.4", "This is version comment"};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{"1.2.3.4", "This is version comment"};
Row row = 0{"1.2.3.4", "This is version comment"};

EXPECT_FALSE(dataProvider.collect_product_version_info(&document2));
}

TEST_F(DataProviderTest, collect_product_version_info_pro_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_product_version_info_pro_test" according to Googletest FAQ

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (3/4)


TEST_F(DataProviderTest, collect_product_version_info_pro_test) {
MockDataProvider dataProvider;
Row row{"1.2.3.4", "This is Pro build version comment"};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{"1.2.3.4", "This is Pro build version comment"};
Row row = 0{"1.2.3.4", "This is Pro build version comment"};

EXPECT_STREQ(iter->value.GetString(), "1.2.3.4-pro");
}

TEST_F(DataProviderTest, collect_plugins_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_plugins_info_test" according to Googletest FAQ

&MockDataProvider::collect_plugins_info);
}

TEST_F(DataProviderTest, collect_components_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_components_info_test" according to Googletest FAQ

&MockDataProvider::collect_components_info);
}

TEST_F(DataProviderTest, collect_uptime_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_uptime_info_test" according to Googletest FAQ


TEST_F(DataProviderTest, collect_uptime_info_test) {
MockDataProvider dataProvider;
Row row{"Uptime", "12345"};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row is not initialized

Suggested change
Row row{"Uptime", "12345"};
Row row = 0{"Uptime", "12345"};

EXPECT_STREQ(iter->value.GetString(), "12345");
}

TEST_F(DataProviderTest, collect_dbs_number_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_dbs_number_info_test" according to Googletest FAQ

&MockDataProvider::collect_dbs_number_info);
}

TEST_F(DataProviderTest, collect_dbs_size_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_dbs_size_info_test" according to Googletest FAQ

&MockDataProvider::collect_dbs_size_info);
}

TEST_F(DataProviderTest, collect_se_usage_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_se_usage_info_test" according to Googletest FAQ

&MockDataProvider::collect_se_usage_info);
}

TEST_F(DataProviderTest, collect_group_replication_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_group_replication_info_test" according to Googletest FAQ

const std::string role_val("role_val");
const std::string db_id_val("db_id_val");
const std::string single_primary_mode_val("single_primary_mode_val");
Row row1{role_val, db_id_val, single_primary_mode_val};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row1 is not initialized

Suggested change
Row row1{role_val, db_id_val, single_primary_mode_val};
Row row1 = 0{role_val, db_id_val, single_primary_mode_val};

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (4/4)

"SELECT COUNT(*) FROM performance_schema.replication_group_members"));

const std::string count_val("count_val");
Row row2{count_val};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row2 is not initialized

Suggested change
Row row2{count_val};
Row row2 = 0{count_val};

Return(false)));

const std::string expected_id("expected_id");
Row row3{expected_id};
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-init-variables ⚠️
variable row3 is not initialized

Suggested change
Row row3{expected_id};
Row row3 = 0{expected_id};

EXPECT_STREQ(iter->value.GetString(), count_val.c_str());
}

TEST_F(DataProviderTest, collect_async_replication_info_test) {
Copy link

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "collect_async_replication_info_test" according to Googletest FAQ

@@ -0,0 +1,8 @@
#include <components/percona_telemetry/logger.h>

Logger::Logger(SERVICE_TYPE(log_builtins) &,
Copy link

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-pro-type-member-init ⚠️
constructor does not initialize these fields: log_level_

bool do_query(const std::string &query, QueryResult *result,
unsigned int *err_no = nullptr,
bool suppress_query_error_log = false);
virtual bool do_query(const std::string &query, QueryResult *result,
Copy link

Choose a reason for hiding this comment

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

⚠️ google-default-arguments ⚠️
default arguments on virtual or override methods are prohibited

Copy link
Collaborator

@percona-ysorokin percona-ysorokin left a comment

Choose a reason for hiding this comment

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

LGTM

@inikep inikep merged commit 8f03f8b into percona:trunk Nov 6, 2024
8 of 23 checks passed
@inikep inikep deleted the TEL-26-trunk branch November 6, 2024 14:26
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