YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/pgwrapper/alter_schema_abort_txn-test.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
13
#include "yb/tserver/tablet_service.h"
14
#include "yb/yql/pgwrapper/pg_mini_test_base.h"
15
16
DECLARE_bool(TEST_fail_alter_schema_after_abort_transactions);
17
18
namespace yb {
19
namespace pgwrapper {
20
21
class AlterSchemaAbortTxnTest : public PgMiniTestBase {
22
 public:
23
0
  void SetUp() override {
24
0
    FLAGS_TEST_fail_alter_schema_after_abort_transactions = true;
25
0
    PgMiniTestBase::SetUp();
26
0
  }
27
};
28
29
0
TEST_F(AlterSchemaAbortTxnTest, YB_DISABLE_TEST_IN_TSAN(AlterSchemaFailure)) {
30
0
  auto resource_conn = ASSERT_RESULT(Connect());
31
0
  ASSERT_OK(resource_conn.Execute("CREATE TABLE p (a INT, b INT)"));
32
0
  ASSERT_OK(resource_conn.Execute("INSERT INTO p VALUES (1)"));
33
34
0
  auto txn_conn = ASSERT_RESULT(Connect());
35
0
  auto ddl_conn = ASSERT_RESULT(Connect());
36
0
  ASSERT_OK(txn_conn.Fetch("SELECT * FROM p"));
37
0
  ASSERT_OK(txn_conn.Execute("BEGIN"));
38
0
  ASSERT_OK(txn_conn.Execute("INSERT INTO p VALUES (2)"));
39
40
0
  ASSERT_NOK(ddl_conn.Execute("ALTER TABLE p ADD COLUMN b TEXT"));
41
42
  // If the above alter failed rather than crashing tserver,
43
  // then this transaction block should commit properly.
44
  // Also, since the alter command failed, this concurrent transaction
45
  // should not get catalog version mismatch error.
46
0
  ASSERT_OK(txn_conn.Execute("COMMIT"));
47
48
49
0
  auto res = ASSERT_RESULT(ddl_conn.FetchFormat("SELECT COUNT(*) FROM $0", "p"));
50
0
  int64_t value = ASSERT_RESULT(GetInt64(res.get(), 0, 0));
51
0
  ASSERT_EQ(value, 2);
52
0
}
53
54
} // namespace pgwrapper
55
} // namespace yb