Skip to content

Commit

Permalink
[pg15-upgrade] test: convert backslash d and comment tests to c++ uni…
Browse files Browse the repository at this point in the history
…t tests

Summary:
Adding `Pg15UpgradeTestBase` class to upgrade from 2.20.2.4 to latest (pg15) and helper functions to keep the cluster in a mixed mode.
Adding a test to check the pg versions at various stages, and one that creates a table with 3 tablets, and 100 row and ensures the row count is correct when queried in mixed mode.
Converted `test_upgrade_backslash_d.sh`, and `test_upgrade_comment.sh` to c++ unit tests.

Fixes to UpgradeTestBase:
- Enabling `ysql_enable_db_catalog_version_mode` and running necessary commands to set up per db catalog mode.
- Disabling `ysql_yb_enable_expression_pushdown`
- Fixed `UpgradeTestBase::RollbackVolatileAutoFlags` to run `RollbackYsqlMajorVersion` AFTER `RestartAllTServersInOldVersion`

Test Plan:
Pg15UpgradeTest.CheckVersion
Pg15UpgradeTest.UpgradeWithOneTable
Pg15UpgradeTest.BackslashD
Pg15UpgradeTest.Comments

Reviewers: tfoucher, telgersma, jason, fizaa

Reviewed By: tfoucher

Subscribers: ybase

Differential Revision: https://phorge.dev.yugabyte.com/D38487
  • Loading branch information
hari90 committed Oct 1, 2024
1 parent 3964770 commit 6623c35
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 190 deletions.
40 changes: 0 additions & 40 deletions pg15_tests/test_upgrade_backslash_d.sh

This file was deleted.

125 changes: 0 additions & 125 deletions pg15_tests/test_upgrade_comment.sh

This file was deleted.

2 changes: 2 additions & 0 deletions src/yb/integration-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ set(INTEGRATION_TESTS_SRCS
xcluster/xcluster_ysql_test_base.cc
xcluster/xcluster_ycql_test_base.cc
xcluster/xcluster_ddl_replication_test_base.cc
upgrade-tests/pg15_upgrade_test_base.cc
upgrade-tests/upgrade_test_base.cc
)

Expand Down Expand Up @@ -260,6 +261,7 @@ ADD_YB_TEST(xcluster/xcluster-test)
ADD_YB_TEST(xcluster/xcluster_outbound_replication_group-itest)
ADD_YB_TEST(retryable_request-test)
ADD_YB_TEST(upgrade-tests/basic_upgrade-test)
ADD_YB_TEST(upgrade-tests/pg15_upgrade-test)

set(YB_TEST_LINK_LIBS_SAVED ${YB_TEST_LINK_LIBS})
set(YB_TEST_LINK_LIBS ${YB_TEST_LINK_LIBS} cassandra)
Expand Down
9 changes: 9 additions & 0 deletions src/yb/integration-tests/external_mini_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,15 @@ void ExternalMiniCluster::RemoveExtraFlagOnTServers(const std::string& flag) {
}
}

Status ExternalMiniCluster::AddAndSetExtraFlag(const std::string& flag, const std::string& value) {
for (const auto& daemon : daemons()) {
daemon->AddExtraFlag(flag, value);
RETURN_NOT_OK_PREPEND(
SetFlag(daemon, flag, value), Format("Failed to set flag on $0", daemon->id()));
}

return Status::OK();
}

uint16_t ExternalMiniCluster::AllocateFreePort() {
// This will take a file lock ensuring the port does not get claimed by another thread/process
Expand Down
4 changes: 4 additions & 0 deletions src/yb/integration-tests/external_mini_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ class ExternalMiniCluster : public MiniClusterBase {
// to get any effect of that change.
void RemoveExtraFlagOnTServers(const std::string& flag);

// Adds the given flag to the extra flags on all servers. Also dynamically sets the flag on the
// running processes. Non runtime flags would still require a restart.
Status AddAndSetExtraFlag(const std::string& flag, const std::string& value);

// Allocates a free port and stores a file lock guarding access to that port into an internal
// array of file locks.
uint16_t AllocateFreePort();
Expand Down
171 changes: 171 additions & 0 deletions src/yb/integration-tests/upgrade-tests/pg15_upgrade-test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Copyright (c) YugabyteDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations
// under the License.
//

#include "yb/integration-tests/upgrade-tests/pg15_upgrade_test_base.h"

#include "yb/yql/pgwrapper/libpq_utils.h"

namespace yb {

class Pg15UpgradeTest : public Pg15UpgradeTestBase {
public:
Pg15UpgradeTest() = default;
};

TEST_F(Pg15UpgradeTest, CheckVersion) {
const auto kSelectVersion = "SELECT version()";
{
auto conn = ASSERT_RESULT(cluster_->ConnectToDB());
auto version = ASSERT_RESULT(conn.FetchRowAsString(kSelectVersion));
ASSERT_STR_CONTAINS(version, old_version_info().version);
}

ASSERT_OK(UpgradeClusterToMixedMode());

{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg15));
auto version = ASSERT_RESULT(conn.FetchRowAsString(kSelectVersion));
ASSERT_STR_CONTAINS(version, current_version_info().version_number());
}
{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg11));
auto version = ASSERT_RESULT(conn.FetchRowAsString(kSelectVersion));
ASSERT_STR_CONTAINS(version, old_version_info().version);
}

ASSERT_OK(FinalizeUpgradeFromMixedMode());

{
auto conn = ASSERT_RESULT(cluster_->ConnectToDB());
auto version = ASSERT_RESULT(conn.FetchRowAsString(kSelectVersion));
ASSERT_STR_CONTAINS(version, current_version_info().version_number());
}
}

TEST_F(Pg15UpgradeTest, SimpleTable) {
const size_t kRowCount = 100;
// Create a table with 3 tablets and kRowCount rows so that each tablet has at least a few rows.
ASSERT_OK(ExecuteStatements(
{"CREATE TABLE t (a INT) SPLIT INTO 3 TABLETS",
Format("INSERT INTO t VALUES(generate_series(1, $0))", kRowCount)}));
static const auto kSelectFromTable = "SELECT * FROM t";

ASSERT_OK(UpgradeClusterToMixedMode());

{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg15));
auto count = ASSERT_RESULT(conn.Fetch(kSelectFromTable));
ASSERT_EQ(PQntuples(count.get()), kRowCount);
}
{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg11));
auto count = ASSERT_RESULT(conn.Fetch(kSelectFromTable));
ASSERT_EQ(PQntuples(count.get()), kRowCount);
}

ASSERT_OK(FinalizeUpgradeFromMixedMode());

// Verify row count from a random tserver.
{
auto conn = ASSERT_RESULT(cluster_->ConnectToDB());
auto count = ASSERT_RESULT(conn.Fetch(kSelectFromTable));
ASSERT_EQ(PQntuples(count.get()), kRowCount);
}
}

TEST_F(Pg15UpgradeTest, BackslashD) {
ASSERT_OK(ExecuteStatement("CREATE TABLE t (a INT)"));
static const auto kBackslashD = "\\d";
static const auto kExpectedResult =
" List of relations\n"
" Schema | Name | Type | Owner \n"
"--------+------+-------+----------\n"
" public | t | table | postgres\n"
"(1 row)\n\n";

auto result = ASSERT_RESULT(ExecuteViaYsqlsh(kBackslashD));
ASSERT_EQ(result, kExpectedResult);

ASSERT_OK(UpgradeClusterToMixedMode());

result = ASSERT_RESULT(ExecuteViaYsqlshOnTs(kBackslashD, kMixedModeTserverPg15));
ASSERT_EQ(result, kExpectedResult);
result = ASSERT_RESULT(ExecuteViaYsqlshOnTs(kBackslashD, kMixedModeTserverPg11));
ASSERT_EQ(result, kExpectedResult);

ASSERT_OK(FinalizeUpgradeFromMixedMode());

// Verify the result from a random tserver.
result = ASSERT_RESULT(ExecuteViaYsqlsh(kBackslashD));
ASSERT_EQ(result, kExpectedResult);
}

TEST_F(Pg15UpgradeTest, Comments) {
const auto kPg11DatabaseComment = "PG11: [db] I came first!";
const auto kPg11TableComment = "PG11: [table] I came first!";
ASSERT_OK(ExecuteStatements(
{"CREATE TABLE t (a int)",
Format("COMMENT ON DATABASE yugabyte IS '$0'", kPg11DatabaseComment),
Format("COMMENT ON TABLE t IS '$0'", kPg11TableComment)}));

ASSERT_OK(UpgradeClusterToMixedMode());

const auto kSelectDatabaseComment =
"SELECT pg_catalog.shobj_description(d.oid, 'pg_database') FROM pg_catalog.pg_database d "
"WHERE datname = 'yugabyte'";
const auto kSelectTableComment =
"SELECT description from pg_description JOIN pg_class on pg_description.objoid = "
"pg_class.oid WHERE relname = 't'";

auto check_pg11_comment = [&](pgwrapper::PGConn& conn) {
auto comment = ASSERT_RESULT(conn.FetchRow<std::string>(kSelectDatabaseComment));
ASSERT_EQ(comment, kPg11DatabaseComment);
comment = ASSERT_RESULT(conn.FetchRow<std::string>(kSelectTableComment));
ASSERT_EQ(comment, kPg11TableComment);
};

{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg15));
ASSERT_NO_FATALS(check_pg11_comment(conn));
}
{
auto conn = ASSERT_RESULT(CreateConnToTs(kMixedModeTserverPg11));
ASSERT_NO_FATALS(check_pg11_comment(conn));
}

ASSERT_OK(FinalizeUpgradeFromMixedMode());

// Check the comment from a random tserver.
{
auto conn = ASSERT_RESULT(cluster_->ConnectToDB());
ASSERT_NO_FATALS(check_pg11_comment(conn));
}

// Update the comment.
const auto kPg15DatabaseComment = "PG15: [db] I am better than you!";
const auto kPg15TableComment = "PG15: [table] I am better than you!";
ASSERT_OK(ExecuteStatements(
{Format("COMMENT ON DATABASE yugabyte IS '$0'", kPg15DatabaseComment),
Format("COMMENT ON TABLE t IS '$0'", kPg15TableComment)}));

// Check the new comment from a random tserver.
{
auto conn = ASSERT_RESULT(cluster_->ConnectToDB());
auto comment = ASSERT_RESULT(conn.FetchRow<std::string>(kSelectDatabaseComment));
ASSERT_EQ(comment, kPg15DatabaseComment);
comment = ASSERT_RESULT(conn.FetchRow<std::string>(kSelectTableComment));
ASSERT_EQ(comment, kPg15TableComment);
}
}

} // namespace yb
Loading

0 comments on commit 6623c35

Please sign in to comment.