diff options
author | Rafi Shamim <rafi@cockroachlabs.com> | 2020-05-07 18:26:24 -0400 |
---|---|---|
committer | Rafi Shamim <rafi@cockroachlabs.com> | 2020-05-12 12:48:35 -0400 |
commit | f935476b3f15dd1032a290b5d3ab12326dd91f24 (patch) | |
tree | 7372785bea5ffe7270113f3e41842d079e829ce5 | |
parent | 14355e9c69eacd38eafc1b24538c316529fe57e2 (diff) | |
download | psycopg2-f935476b3f15dd1032a290b5d3ab12326dd91f24.tar.gz |
Handle failure in setup of ConnectionTwoPhaseTest
Previously, this test had a bug, because if the CREATE TABLE statement
failed, the setup would fail without committing or rolling back the
active transaction.
-rwxr-xr-x | tests/test_connection.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py index f1668d5..8236801 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -913,9 +913,11 @@ class ConnectionTwoPhaseTests(ConnectingTestCase): cur.execute("DROP TABLE test_tpc;") except psycopg2.ProgrammingError: cnn.rollback() - cur.execute("CREATE TABLE test_tpc (data text);") - cnn.commit() - cnn.close() + try: + cur.execute("CREATE TABLE test_tpc (data text);") + cnn.commit() + finally: + cnn.close() def count_xacts(self): """Return the number of prepared xacts currently in the test db.""" |