Skip to content

Commit f60aa9f

Browse files
committed
[yugabyte#24420] YSQL: Fix the NoWaitForRPCOnTermination unit test
Summary: The `NoWaitForRPCOnTermination` unit test expects that connection will be closed while query processing. The test checks that raised error will have particular message `terminating connection due to administrator command`. This error message with this substring is really logged by postgres in logs, but the postgres process may not sent it to the user. It may just close the connection. As a result client may only detect general connection close error. Solution: rework the check that connection was closed. Jira: DB-13330 Test Plan: Run existing unit test ``` ./yb_build.sh --gtest_filter PgMiniTest.NoWaitForRPCOnTermination ``` Reviewers: pjain, jason, kramanathan Reviewed By: kramanathan Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D39005
1 parent 82d5a82 commit f60aa9f

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/yb/yql/pgwrapper/pg_mini-test.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,11 +2175,7 @@ TEST_F(PgMiniTest, CompactionAfterDBDrop) {
21752175
// The test checks that YSQL doesn't wait for sent RPC response in case of process termination.
21762176
TEST_F(PgMiniTest, NoWaitForRPCOnTermination) {
21772177
auto conn = ASSERT_RESULT(Connect());
2178-
ASSERT_OK(conn.Execute("CREATE TABLE t(k INT PRIMARY KEY) SPLIT INTO 1 TABLETS"));
2179-
constexpr auto kRows = RegularBuildVsDebugVsSanitizers(1000000, 100000, 30000);
2180-
ASSERT_OK(conn.ExecuteFormat(
2181-
"INSERT INTO t SELECT s FROM generate_series(1, $0) AS s", kRows));
2182-
constexpr auto kLongTimeQuery = "SELECT COUNT(*) FROM t";
2178+
constexpr auto kLongTimeQuery = "SELECT pg_sleep(30)";
21832179
std::atomic<MonoTime> termination_start;
21842180
MonoTime termination_end;
21852181
{
@@ -2192,11 +2188,12 @@ TEST_F(PgMiniTest, NoWaitForRPCOnTermination) {
21922188
const auto deadline = MonoTime::Now() + MonoDelta::FromSeconds(30);
21932189
while (MonoTime::Now() < deadline) {
21942190
const auto local_termination_start = MonoTime::Now();
2195-
auto res = ASSERT_RESULT(thread_conn.FetchFormat(
2196-
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE query like '$0'",
2197-
kLongTimeQuery));
2198-
auto lines = PQntuples(res.get());
2199-
if (lines) {
2191+
const auto lines = ASSERT_RESULT(thread_conn.FetchRows<bool>(
2192+
Format(
2193+
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE query like '$0'",
2194+
kLongTimeQuery)));
2195+
if (!lines.empty()) {
2196+
ASSERT_TRUE(lines.size() == 1 && lines.front());
22002197
termination_start.store(local_termination_start, std::memory_order_release);
22012198
break;
22022199
}
@@ -2206,8 +2203,8 @@ TEST_F(PgMiniTest, NoWaitForRPCOnTermination) {
22062203
latch.Wait();
22072204
const auto res = conn.Fetch(kLongTimeQuery);
22082205
ASSERT_NOK(res);
2209-
ASSERT_STR_CONTAINS(res.status().ToString(),
2210-
"terminating connection due to administrator command");
2206+
ASSERT_TRUE(res.status().IsNetworkError());
2207+
ASSERT_STR_CONTAINS(res.status().ToString(), "server closed the connection unexpectedly");
22112208
termination_end = MonoTime::Now();
22122209
}
22132210
const auto termination_duration =

0 commit comments

Comments
 (0)