From c30c3b1a5216d281db84f9fa48466edaf7a26d1e Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Fri, 27 Dec 2019 22:32:08 +0100 Subject: [PATCH] add check for prepared transactions in two_phase_transactions requirement --- README.unittests.rst | 5 +++++ doc/build/changelog/unreleased_13/5057.rst | 8 ++++++++ test/requirements.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 doc/build/changelog/unreleased_13/5057.rst diff --git a/README.unittests.rst b/README.unittests.rst index cd83ef4100..682805bbb3 100644 --- a/README.unittests.rst +++ b/README.unittests.rst @@ -200,6 +200,11 @@ Additional steps specific to individual databases are as follows:: grant dba to scott; + Tests for two phase transactions require support for prepared transactions. To include them + the feature must be enabled by setting max_prepared_transactions to a value > 0. + See documentation for details + https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS + MSSQL: Tests that involve multiple connections require Snapshot Isolation ability implemented on the test database in order to prevent deadlocks that will occur with record locking isolation. This feature is only available diff --git a/doc/build/changelog/unreleased_13/5057.rst b/doc/build/changelog/unreleased_13/5057.rst new file mode 100644 index 0000000000..d60ad0b24e --- /dev/null +++ b/doc/build/changelog/unreleased_13/5057.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: test, postgresql + :tickets: 5057 + + Improve detection of two phase transactions requirements by checking that + the database supports prepared transactions. This mainly affects postgresql + that has the feature disabled by default + diff --git a/test/requirements.py b/test/requirements.py index d9e73c898e..de23c25d75 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -645,6 +645,19 @@ class DefaultRequirements(SuiteRequirements): def two_phase_transactions(self): """Target database must support two-phase transactions.""" + def prepared_transaction(config): + from sqlalchemy import select, exc + + with config.db.connect() as conn: + try: + trans = conn.begin_twophase() + conn.execute(select([1])) + trans.prepare() + trans.commit() + return True + except exc.OperationalError: + return False + return skip_if( [ no_support("firebird", "no SA implementation"), @@ -672,6 +685,8 @@ class DefaultRequirements(SuiteRequirements): "(late 2016), disabling for now", ), ] + ) + only_if( + prepared_transaction, "missing support for prepared transaction" ) @property -- 2.47.3