-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pg15-upgrade] test: convert backslash d and comment tests to c++ uni…
…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
Showing
10 changed files
with
433 additions
and
190 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
src/yb/integration-tests/upgrade-tests/pg15_upgrade-test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.