Implement pre and post scenario SQL execution in subscription ResQL tests to manage publication lifecycle. #8932
parent
04024c7f61
commit
c6af61afd3
|
|
@ -13,7 +13,7 @@
|
||||||
add empty bracket with table name
|
add empty bracket with table name
|
||||||
#}
|
#}
|
||||||
{% set empty_bracket = ""%}
|
{% set empty_bracket = ""%}
|
||||||
{% if data.coll_inherits|length == 0 and data.columns|length == 0 and not data.typname and not data.like_relation and data.primary_key|length == 0 and data.unique_constraint|length == 0 and data.foreign_key|length == 0 and data.check_constraint|length == 0 and data.exclude_constraint|length == 0 %}
|
{% if not (data.coll_inherits or data.columns or data.typname or data.like_relation or data.primary_key or data.unique_constraint or data.foreign_key or data.check_constraint or data.exclude_constraint) %}
|
||||||
{% set empty_bracket = "\n(\n)"%}
|
{% set empty_bracket = "\n(\n)"%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% set with_clause = false%}
|
{% set with_clause = false%}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
"endpoint": "NODE-publication.obj",
|
"endpoint": "NODE-publication.obj",
|
||||||
"sql_endpoint": "NODE-publication.sql_id",
|
"sql_endpoint": "NODE-publication.sql_id",
|
||||||
"msql_endpoint": "NODE-publication.msql",
|
"msql_endpoint": "NODE-publication.msql",
|
||||||
|
"precondition_sql": "SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription' UNION ALL SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') AND pg_create_logical_replication_slot('test_create_subscription', 'pgoutput', false) IS NOT NULL LIMIT 1;",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "test_publication",
|
"name": "test_publication",
|
||||||
"evnt_insert": true,
|
"evnt_insert": true,
|
||||||
|
|
@ -116,7 +117,8 @@
|
||||||
"endpoint": "NODE-subscription.delete_id",
|
"endpoint": "NODE-subscription.delete_id",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "test_create_subscription"
|
"name": "test_create_subscription"
|
||||||
}
|
},
|
||||||
|
"post_scenario_sql": "SELECT 1 WHERE EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') AND (SELECT pg_drop_replication_slot('test_create_subscription')) IS NOT NULL UNION ALL SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') LIMIT 1;"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
"endpoint": "NODE-subscription.obj",
|
"endpoint": "NODE-subscription.obj",
|
||||||
"sql_endpoint": "NODE-subscription.sql_id",
|
"sql_endpoint": "NODE-subscription.sql_id",
|
||||||
"msql_endpoint": "NODE-subscription.msql",
|
"msql_endpoint": "NODE-subscription.msql",
|
||||||
|
"precondition_sql": "SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription' UNION ALL SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') AND pg_create_logical_replication_slot('test_create_subscription', 'pgoutput', false) IS NOT NULL LIMIT 1;",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "test_create_subscription",
|
"name": "test_create_subscription",
|
||||||
"subowner": "postgres",
|
"subowner": "postgres",
|
||||||
|
|
@ -66,7 +67,8 @@
|
||||||
"endpoint": "NODE-subscription.delete_id",
|
"endpoint": "NODE-subscription.delete_id",
|
||||||
"data": {
|
"data": {
|
||||||
"name": "test_create_subscription"
|
"name": "test_create_subscription"
|
||||||
}
|
},
|
||||||
|
"post_scenario_sql": "SELECT 1 WHERE EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') AND (SELECT pg_drop_replication_slot('test_create_subscription')) IS NOT NULL UNION ALL SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_create_subscription') LIMIT 1;"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,35 +95,6 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
||||||
# Added line break after scenario name
|
# Added line break after scenario name
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
# Create replication slot if it does not exist for the
|
|
||||||
# RESQL test-cases of Subscriptions for PGv17 and above
|
|
||||||
if self.server_information['server_version'] >= 170000:
|
|
||||||
try:
|
|
||||||
self.get_db_connection()
|
|
||||||
pg_cursor = self.connection.cursor()
|
|
||||||
pg_cursor.execute("""
|
|
||||||
SELECT 1 FROM pg_replication_slots
|
|
||||||
WHERE slot_name = 'test_create_subscription'
|
|
||||||
""")
|
|
||||||
exists = pg_cursor.fetchone()
|
|
||||||
if not exists:
|
|
||||||
pg_cursor.execute("""
|
|
||||||
SELECT pg_create_logical_replication_slot(
|
|
||||||
'test_create_subscription',
|
|
||||||
'pgoutput',
|
|
||||||
failover := false
|
|
||||||
);
|
|
||||||
""")
|
|
||||||
self.connection.commit()
|
|
||||||
print("Replication slot "
|
|
||||||
"'test_create_subscription' created.")
|
|
||||||
else:
|
|
||||||
print("Replication slot 'test_create_subscription' "
|
|
||||||
"already exists.")
|
|
||||||
pg_cursor.close()
|
|
||||||
except Exception as e:
|
|
||||||
print("Could not create replication slot: ", e)
|
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
""" Create the module list on which reverse engineeredsql test
|
""" Create the module list on which reverse engineeredsql test
|
||||||
cases will be executed."""
|
cases will be executed."""
|
||||||
|
|
@ -182,30 +153,6 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
||||||
# Check the final status of the test case
|
# Check the final status of the test case
|
||||||
self.assertEqual(self.final_test_status, True)
|
self.assertEqual(self.final_test_status, True)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
# Drop the replication slot created for the RESQL test-cases of
|
|
||||||
# Subscriptions, if it exists before disconnecting for PGv17 and above
|
|
||||||
if self.server_information['server_version'] >= 170000:
|
|
||||||
try:
|
|
||||||
self.get_db_connection()
|
|
||||||
pg_cursor = self.connection.cursor()
|
|
||||||
pg_cursor.execute("""
|
|
||||||
SELECT 1 FROM pg_replication_slots
|
|
||||||
WHERE slot_name = 'test_create_subscription'
|
|
||||||
""")
|
|
||||||
exists = pg_cursor.fetchone()
|
|
||||||
if exists:
|
|
||||||
pg_cursor.execute("""
|
|
||||||
SELECT
|
|
||||||
pg_drop_replication_slot('test_create_subscription');
|
|
||||||
""")
|
|
||||||
self.connection.commit()
|
|
||||||
print("Replication slot "
|
|
||||||
"'test_create_subscription' dropped.")
|
|
||||||
pg_cursor.close()
|
|
||||||
except Exception as e:
|
|
||||||
print("Could not drop replication slot: ", e)
|
|
||||||
|
|
||||||
database_utils.disconnect_database(
|
database_utils.disconnect_database(
|
||||||
self, self.server_information['server_id'],
|
self, self.server_information['server_id'],
|
||||||
self.server_information['db_id'])
|
self.server_information['db_id'])
|
||||||
|
|
@ -653,7 +600,10 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
|
||||||
try:
|
try:
|
||||||
pg_cursor.execute(precondition_sql)
|
pg_cursor.execute(precondition_sql)
|
||||||
precondition_result = pg_cursor.fetchone()
|
precondition_result = pg_cursor.fetchone()
|
||||||
if len(precondition_result) >= 1 and precondition_result[0] == '1':
|
if ((len(precondition_result) >= 1 and
|
||||||
|
precondition_result[0] == '1') or
|
||||||
|
(isinstance(precondition_result, tuple) and
|
||||||
|
precondition_result[0] == 1)):
|
||||||
precondition_flag = True
|
precondition_flag = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue