Skip to content

Commit

Permalink
Extend behave tests with nostream feature (patroni#3036)
Browse files Browse the repository at this point in the history
Check state and permanent logical replication slots behaviour
  • Loading branch information
hughcapet authored Mar 29, 2024
1 parent 9b237b3 commit ae53260
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
21 changes: 12 additions & 9 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,18 @@ def _make_patroni_test_config(self, name, custom_config):
'parameters': {
'wal_keep_segments': 100,
'archive_mode': 'on',
'archive_command': (PatroniPoolController.ARCHIVE_RESTORE_SCRIPT
+ ' --mode archive '
+ '--dirname {} --filename %f --pathname %p').format(
os.path.join(self._work_directory, 'data', 'wal_archive'))
'archive_command':
(PatroniPoolController.ARCHIVE_RESTORE_SCRIPT
+ ' --mode archive '
+ '--dirname {} --filename %f --pathname %p').format(
os.path.join(self._work_directory, 'data',
f'wal_archive{str(self._citus_group or "")}')).replace('\\', '/'),
'restore_command':
(PatroniPoolController.ARCHIVE_RESTORE_SCRIPT
+ ' --mode restore '
+ '--dirname {} --filename %f --pathname %p').format(
os.path.join(self._work_directory, 'data',
f'wal_archive{str(self._citus_group or "")}')).replace('\\', '/')
}
}
}
Expand Down Expand Up @@ -928,11 +936,6 @@ def bootstrap_from_backup_no_leader(self, name, cluster_name):
custom_config = {
'scope': cluster_name,
'postgresql': {
'recovery_conf': {
'restore_command': (self.ARCHIVE_RESTORE_SCRIPT + ' --mode restore '
+ '--dirname {} --filename %f --pathname %p')
.format(os.path.join(self.patroni_path, 'data', 'wal_archive').replace('\\', '/'))
},
'create_replica_methods': ['no_leader_bootstrap'],
'no_leader_bootstrap': self.backup_restore_config({'no_leader': '1'})
}
Expand Down
18 changes: 18 additions & 0 deletions features/nostream_node.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: nostream node

Scenario: check nostream node is recovering from archive
When I start postgres0
And I configure and start postgres1 with a tag nostream true
Then "members/postgres1" key in DCS has replication_state=in archive recovery after 10 seconds
And replication works from postgres0 to postgres1 after 30 seconds

@slot-advance
Scenario: check permanent logical replication slots are not copied
When I issue a PATCH request to http://127.0.0.1:8008/config with {"postgresql": {"parameters": {"wal_level": "logical"}}, "slots":{"test_logical":{"type":"logical","database":"postgres","plugin":"test_decoding"}}}
Then I receive a response code 200
When I run patronictl.py restart batman postgres0 --force
Then postgres0 has a logical replication slot named test_logical with the test_decoding plugin after 10 seconds
When I configure and start postgres2 with a tag replicatefrom postgres1
Then "members/postgres2" key in DCS has replication_state=streaming after 10 seconds
And postgres1 does not have a replication slot named test_logical
And postgres2 does not have a replication slot named test_logical
3 changes: 2 additions & 1 deletion features/standby_cluster.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feature: standby cluster
Scenario: Detach exiting node from the cluster
When I shut down postgres1
Then postgres0 is a leader after 10 seconds
And "members/postgres0" key in DCS has role=master after 3 seconds
And "members/postgres0" key in DCS has role=master after 5 seconds
When I issue a GET request to http://127.0.0.1:8008/
Then I receive a response code 200

Expand All @@ -47,6 +47,7 @@ Feature: standby cluster
And there is a postgres1_cb.log with "on_role_change standby_leader batman1" in postgres1 data directory
When I start postgres2 in a cluster batman1
Then postgres2 role is the replica after 24 seconds
And postgres2 is replicating from postgres1 after 10 seconds
And table foo is present on postgres2 after 20 seconds
When I issue a GET request to http://127.0.0.1:8010/patroni
Then I receive a response code 200
Expand Down
10 changes: 7 additions & 3 deletions features/steps/basic_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ def kill_postgres(context, name):
return context.pctl.stop(name, kill=True, postgres=True)


def get_wal_name(context, pg_name):
version = context.pctl.query(pg_name, "SHOW server_version_num").fetchone()[0]
return 'xlog' if int(version) / 10000 < 10 else 'wal'


@step('I add the table {table_name:w} to {pg_name:w}')
def add_table(context, table_name, pg_name):
# parse the configuration file and get the port
try:
context.pctl.query(pg_name, "CREATE TABLE public.{0}()".format(table_name))
context.pctl.query(pg_name, "SELECT pg_switch_{0}()".format(get_wal_name(context, pg_name)))
except pg.Error as e:
assert False, "Error creating table {0} on {1}: {2}".format(table_name, pg_name, e)

Expand All @@ -59,9 +65,7 @@ def add_table(context, table_name, pg_name):
def toggle_wal_replay(context, action, pg_name):
# pause or resume the wal replay process
try:
version = context.pctl.query(pg_name, "SHOW server_version_num").fetchone()[0]
wal_name = 'xlog' if int(version) / 10000 < 10 else 'wal'
context.pctl.query(pg_name, "SELECT pg_{0}_replay_{1}()".format(wal_name, action))
context.pctl.query(pg_name, "SELECT pg_{0}_replay_{1}()".format(get_wal_name(context, pg_name), action))
except pg.Error as e:
assert False, "Error during {0} wal recovery on {1}: {2}".format(action, pg_name, e)

Expand Down

0 comments on commit ae53260

Please sign in to comment.