8000 Synchronous standbys by zilder · Pull Request #46 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Synchronous standbys #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next com 8000 mit
fix test_synchronous_replication so it could pass on all supported ve…
…rsions of Postgres
  • Loading branch information
zilder committed Jun 1, 2018
commit a1fcfaca2bca74c8c0bcb9fa90baf96f12e12647
20 changes: 15 additions & 5 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,11 @@ def set_synchronous_standbys(self, standbys):

Args:
standbys: either :class:`.First` or :class:`.Any` object specifying
sychronization parameters. It is also possible to pass simply
a list of replicas which would be equivalent to passing
``First(1, <list>)``
sychronization parameters or just a plain list of
:class:`.PostgresNode`s replicas which would be equivalent
to passing ``First(1, <list>)``. For PostgreSQL 9.5 and below
it is only possible to specify a plain list of standbys as
`FIRST` and `ANY` keywords aren't supported.

Example::

Expand All @@ -1049,8 +1051,16 @@ def set_synchronous_standbys(self, standbys):
master.restart()

"""
if isinstance(standbys, Iterable):
standbys = First(1, standbys)
if pg_version_ge('9.6'):
if isinstance(standbys, Iterable):
standbys = First(1, standbys)
else:
if isinstance(standbys, Iterable):
standbys = u", ".join(
u"\"{}\"".format(r.name) for r in standbys)
else:
raise TestgresException("Feature isn't supported in "
"Postgres 9.5 and below")

self.append_conf("synchronous_standby_names = '{}'".format(standbys))

Expand Down
30 changes: 19 additions & 11 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,12 @@ def test_replicate(self):

def test_synchronous_replication(self):
with get_new_node() as master:
old_version = not pg_version_ge('9.6')

master.init(allow_streaming=True).start()
master.append_conf('synchronous_commit = remote_apply')

if not old_version:
master.append_conf('synchronous_commit = remote_apply')

# create standby
with master.replicate() as standby1, master.replicate() as standby2:
Expand All @@ -424,16 +428,20 @@ def test_synchronous_replication(self):
# set synchronous_standby_names
master.set_synchronous_standbys([standby1, standby2])
master.restart()
master.safe_psql('create table abc(a int)')

# Create a large transaction that will take some time to apply
# on standby to check that it applies synchronously
# (If set synchronous_commit to 'on' or other lower level then
# standby most likely won't catchup so fast and test will fail)
master.safe_psql(
'insert into abc select generate_series(1, 1000000)')
res = standby1.safe_psql('select count(*) from abc')
self.assertEqual(res, b'1000000\n')

# the following part of the test is only applicable to newer
# versions of PostgresQL
if not old_version:
master.safe_psql('create table abc(a int)')

# Create a large transaction that will take some time to apply
# on standby to check that it applies synchronously
# (If set synchronous_commit to 'on' or other lower level then
# standby most likely won't catchup so fast and test will fail)
master.safe_psql(
'insert into abc select generate_series(1, 1000000)')
res = standby1.safe_psql('select count(*) from abc')
self.assertEqual(res, b'1000000\n')

def test_replication_slots(self):
with get_new_node() as node:
Expand Down
0