src/yb/yql/pgwrapper/pg_libpq-test.cc
// Test for ensuring that transaction conflicts work as expected for colocated tables.
// Related to https://github.com/yugabyte/yugabyte-db/issues/3251.
Test for ensuring that transaction conflicts work as expected for colocated tables.
Test for ensuring that transaction conflicts work as expected for colocated tables .
TEST_F(PgLibPqTest, YB_DISABLE_TEST_IN_TSAN(TxnConflictsForColocatedTables)) {
  auto conn = ASSERT_RESULT(Connect());
  ASSERT_OK(conn.Execute("CREATE DATABASE test_db WITH colocated = true"));
  auto conn1 = ASSERT_RESULT(ConnectToDB("test_db"));
  auto conn2 = ASSERT_RESULT(ConnectToDB("test_db"));
  ASSERT_OK(conn1.Execute("CREATE TABLE t (a INT, PRIMARY KEY (a ASC))"));
  ASSERT_OK(conn1.Execute("INSERT INTO t(a) VALUES(1)"));
  ASSERT_OK(conn1.StartTransaction(IsolationLevel::SERIALIZABLE_ISOLATION));
  auto res = ASSERT_RESULT(conn1.Fetch("SELECT * FROM t FOR UPDATE"));
  ASSERT_EQ(PQntuples(res.get()), 1);
  ASSERT_OK(conn2.Execute("DELETE FROM t WHERE a = 1"));
  auto status = conn1.CommitTransaction();
  ASSERT_FALSE(status.ok());
  ASSERT_STR_CONTAINS(status.ToString(), "Operation expired");
  ASSERT_OK(conn1.Execute("CREATE TABLE t2 (a INT, PRIMARY KEY (a ASC))"));
  ASSERT_OK(conn1.Execute("INSERT INTO t(a) VALUES(1)"));
  ASSERT_OK(conn1.Execute("INSERT INTO t2(a) VALUES(1)"));
  ASSERT_OK(conn1.StartTransaction(IsolationLevel::SERIALIZABLE_ISOLATION));
  ASSERT_OK(conn2.StartTransaction(IsolationLevel::SERIALIZABLE_ISOLATION));
  res = ASSERT_RESULT(conn1.Fetch("SELECT * FROM t FOR UPDATE"));
  ASSERT_EQ(PQntuples(res.get()), 1);
  res = ASSERT_RESULT(conn2.Fetch("SELECT * FROM t2 FOR UPDATE"));
  ASSERT_EQ(PQntuples(res.get()), 1);
  ASSERT_OK(conn1.CommitTransaction());
  ASSERT_OK(conn2.CommitTransaction());
}
TEST_F ( PgLibPqTest , YB_DISABLE_TEST_IN_TSAN ( TxnConflictsForColocatedTables ) ) { auto conn = ASSERT_RESULT ( Connect ( ) ) ; ASSERT_OK ( conn . Execute ( " " ) ) ; auto conn1 = ASSERT_RESULT ( ConnectToDB ( " " ) ) ; auto conn2 = ASSERT_RESULT ( ConnectToDB ( " " ) ) ; ASSERT_OK ( conn1 . Execute ( " " ) ) ; ASSERT_OK ( conn1 . Execute ( " " ) ) ; ASSERT_OK ( conn1 . StartTransaction ( IsolationLevel :: SERIALIZABLE_ISOLATION ) ) ; auto res = ASSERT_RESULT ( conn1 . Fetch ( " " ) ) ; ASSERT_EQ ( PQntuples ( res . get ( ) ) , 1 ) ; ASSERT_OK ( conn2 . Execute ( " " ) ) ; auto status = conn1 . CommitTransaction ( ) ; ASSERT_FALSE ( status . ok ( ) ) ; ASSERT_STR_CONTAINS ( status . ToString ( ) , " " ) ; ASSERT_OK ( conn1 . Execute ( " " ) ) ; ASSERT_OK ( conn1 . Execute ( " " ) ) ; ASSERT_OK ( conn1 . Execute ( " " ) ) ; ASSERT_OK ( conn1 . StartTransaction ( IsolationLevel :: SERIALIZABLE_ISOLATION ) ) ; ASSERT_OK ( conn2 . StartTransaction ( IsolationLevel :: SERIALIZABLE_ISOLATION ) ) ; res = ASSERT_RESULT ( conn1 . Fetch ( " " ) ) ; ASSERT_EQ ( PQntuples ( res . get ( ) ) , 1 ) ; res = ASSERT_RESULT ( conn2 . Fetch ( " " ) ) ; ASSERT_EQ ( PQntuples ( res . get ( ) ) , 1 ) ; ASSERT_OK ( conn1 . CommitTransaction ( ) ) ; ASSERT_OK ( conn2 . CommitTransaction ( ) ) ; }
Test for ensuring that transaction conflicts work as expected for colocated tables.
Test for ensuring that transaction conflicts work as expected for colocated tables .
// From conn1, select the row in UPDATE row lock mode. From conn2, delete the row. // Ensure that conn1's transaction will detect a conflict at the time of commit. // Ensure that reads to separate tables in a colocated database do not conflict.