Skip to content

Commit e904f0d

Browse files
committed
Fixed Python test cases, set wal_level to ‘logical’ in the YAML files, and updated the replication slot code in test_resql.py to work with PostgreSQL v17 and above.
1 parent 94540a6 commit e904f0d

File tree

3 files changed

+60
-42
lines changed

3 files changed

+60
-42
lines changed

.github/workflows/run-python-tests-epas.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
sudo su -c "echo local all all trust > /etc/edb-as/${{ matrix.pgver }}/main/pg_hba.conf"
100100
sudo sed -i "s/port = 544[0-9]/port = 58${{ matrix.pgver }}/g" /etc/edb-as/${{ matrix.pgver }}/main/postgresql.conf
101101
sudo sed -i "s/shared_preload_libraries = '/shared_preload_libraries = '\$libdir\/plugin_debugger,/g" /etc/edb-as/${{ matrix.pgver }}/main/postgresql.conf
102+
echo "wal_level = logical" | sudo tee -a /etc/edb-as/${{ matrix.pgver }}/main/postgresql.conf
102103
sudo su - enterprisedb -c "mkdir -p /var/run/edb-as/${{ matrix.pgver }}-main.epas_stat_tmp"
103104
sudo systemctl restart edb-as@${{ matrix.pgver }}-main
104105
@@ -107,6 +108,12 @@ jobs:
107108
sleep 2
108109
done
109110
111+
- name: Start PostgreSQL on Windows
112+
if: ${{ matrix.os == 'windows-latest' }}
113+
run: |
114+
echo wal_level = logical >> "C:\EPAS\${{ matrix.pgver }}\data\postgresql.conf"
115+
shell: cmd
116+
110117
- name: Create pgagent extension on Linux
111118
if: ${{ matrix.os == 'ubuntu-22.04' && matrix.pgver <= 16 }}
112119
run: psql -U enterprisedb -d postgres -p 58${{ matrix.pgver }} -c 'CREATE EXTENSION IF NOT EXISTS pgagent;'

.github/workflows/run-python-tests-pg.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ jobs:
109109
sudo su -c "echo local all all trust > /etc/postgresql/${{ matrix.pgver }}/main/pg_hba.conf"
110110
sudo sed -i "s/port = 543[0-9]/port = 59${{ matrix.pgver }}/g" /etc/postgresql/${{ matrix.pgver }}/main/postgresql.conf
111111
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = '\$libdir\/plugin_debugger'/g" /etc/postgresql/${{ matrix.pgver }}/main/postgresql.conf
112+
echo "wal_level = logical" | sudo tee -a /etc/postgresql/${{ matrix.pgver }}/main/postgresql.conf
112113
sudo su - postgres -c "/usr/lib/postgresql/${{ matrix.pgver }}/bin/postgres -D /var/lib/postgresql/${{ matrix.pgver }}/main -c config_file=/etc/postgresql/${{ matrix.pgver }}/main/postgresql.conf &"
113114
114115
until sudo runuser -l postgres -c "pg_isready -p 59${{ matrix.pgver }}" 2>/dev/null; do
@@ -125,6 +126,8 @@ jobs:
125126
run: |
126127
echo local all all trust > /opt/homebrew/var/postgresql@${{ matrix.pgver }}/pg_hba.conf
127128
sed -i '' "s/#port = 543[0-9]/port = 59${{ matrix.pgver }}/g" /opt/homebrew/var/postgresql@${{ matrix.pgver }}/postgresql.conf
129+
# Add wal_level = logical
130+
echo "wal_level = logical" >> /opt/homebrew/var/postgresql@${{ matrix.pgver }}/postgresql.conf
128131
brew services restart postgresql@${{ matrix.pgver }}
129132
130133
until /opt/homebrew/opt/postgresql@${{ matrix.pgver }}/bin/pg_isready -p 59${{ matrix.pgver }} 2>/dev/null; do
@@ -134,6 +137,12 @@ jobs:
134137
135138
psql postgres -p 59${{ matrix.pgver }} -c 'CREATE ROLE postgres SUPERUSER LOGIN;'
136139
140+
- name: Start PostgreSQL on Windows
141+
if: ${{ matrix.os == 'windows-latest' }}
142+
run: |
143+
echo wal_level = logical >> "C:\PostgreSQL\${{ matrix.pgver }}\data\postgresql.conf"
144+
shell: cmd
145+
137146
- name: Install Python dependencies on Linux and macOS
138147
if: ${{ matrix.os == 'macos-latest' || matrix.os == 'ubuntu-22.04' }}
139148
run: make install-python-testing

web/regression/re_sql/tests/test_resql.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,33 @@ def setUp(self):
9595
# Added line break after scenario name
9696
print("")
9797

98-
# Create replication slot if it does not exist
99-
# for the RESQL test-cases of Subscriptions
100-
try:
101-
self.get_db_connection()
102-
pg_cursor = self.connection.cursor()
103-
pg_cursor.execute("""
104-
SELECT 1 FROM pg_replication_slots
105-
WHERE slot_name = 'test_create_subscription'
106-
""")
107-
exists = pg_cursor.fetchone()
108-
if not exists:
98+
# Create replication slot if it does not exist for the
99+
# RESQL test-cases of Subscriptions for PGv17 and above
100+
if self.server_information['server_version'] >= 170000:
101+
try:
102+
self.get_db_connection()
103+
pg_cursor = self.connection.cursor()
109104
pg_cursor.execute("""
110-
SELECT pg_create_logical_replication_slot(
111-
'test_create_subscription',
112-
'pgoutput',
113-
failover := false
114-
);
105+
SELECT 1 FROM pg_replication_slots
106+
WHERE slot_name = 'test_create_subscription'
115107
""")
116-
self.connection.commit()
117-
print("Replication slot 'test_create_subscription' created.")
118-
else:
119-
print("Replication slot 'test_create_subscription' "
120-
"already exists.")
121-
pg_cursor.close()
122-
except Exception as e:
123-
print("Could not create replication slot: ", e)
108+
exists = pg_cursor.fetchone()
109+
if not exists:
110+
pg_cursor.execute("""
111+
SELECT pg_create_logical_replication_slot(
112+
'test_create_subscription',
113+
'pgoutput',
114+
failover := false
115+
);
116+
""")
117+
self.connection.commit()
118+
print("Replication slot 'test_create_subscription' created.")
119+
else:
120+
print("Replication slot 'test_create_subscription' "
121+
"already exists.")
122+
pg_cursor.close()
123+
except Exception as e:
124+
print("Could not create replication slot: ", e)
124125

125126
def runTest(self):
126127
""" Create the module list on which reverse engineeredsql test
@@ -181,26 +182,27 @@ def runTest(self):
181182
self.assertEqual(self.final_test_status, True)
182183

183184
def tearDown(self):
184-
# Drop the replication slot created for the RESQL
185-
# test-cases of Subscriptions, if it exists before disconnecting
186-
try:
187-
self.get_db_connection()
188-
pg_cursor = self.connection.cursor()
189-
pg_cursor.execute("""
190-
SELECT 1 FROM pg_replication_slots
191-
WHERE slot_name = 'test_create_subscription'
192-
""")
193-
exists = pg_cursor.fetchone()
194-
if exists:
185+
# Drop the replication slot created for the RESQL test-cases of
186+
# Subscriptions, if it exists before disconnecting for PGv17 and above
187+
if self.server_information['server_version'] >= 170000:
188+
try:
189+
self.get_db_connection()
190+
pg_cursor = self.connection.cursor()
195191
pg_cursor.execute("""
196-
SELECT
197-
pg_drop_replication_slot('test_create_subscription');
192+
SELECT 1 FROM pg_replication_slots
193+
WHERE slot_name = 'test_create_subscription'
198194
""")
199-
self.connection.commit()
200-
print("Replication slot 'test_create_subscription' dropped.")
201-
pg_cursor.close()
202-
except Exception as e:
203-
print("Could not drop replication slot: ", e)
195+
exists = pg_cursor.fetchone()
196+
if exists:
197+
pg_cursor.execute("""
198+
SELECT
199+
pg_drop_replication_slot('test_create_subscription');
200+
""")
201+
self.connection.commit()
202+
print("Replication slot 'test_create_subscription' dropped.")
203+
pg_cursor.close()
204+
except Exception as e:
205+
print("Could not drop replication slot: ", e)
204206

205207
database_utils.disconnect_database(
206208
self, self.server_information['server_id'],

0 commit comments

Comments
 (0)