Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1fcfac

Browse files
committed
fix test_synchronous_replication so it could pass on all supported versions of Postgres
1 parent0819053 commita1fcfac

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

‎testgres/node.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,11 @@ def set_synchronous_standbys(self, standbys):
10341034
10351035
Args:
10361036
standbys: either :class:`.First` or :class:`.Any` object specifying
1037-
sychronization parameters. It is also possible to pass simply
1038-
a list of replicas which would be equivalent to passing
1039-
``First(1, <list>)``
1037+
sychronization parameters or just a plain list of
1038+
:class:`.PostgresNode`s replicas which would be equivalent
1039+
to passing ``First(1, <list>)``. For PostgreSQL 9.5 and below
1040+
it is only possible to specify a plain list of standbys as
1041+
`FIRST` and `ANY` keywords aren't supported.
10401042
10411043
Example::
10421044
@@ -1049,8 +1051,16 @@ def set_synchronous_standbys(self, standbys):
10491051
master.restart()
10501052
10511053
"""
1052-
ifisinstance(standbys,Iterable):
1053-
standbys=First(1,standbys)
1054+
ifpg_version_ge('9.6'):
1055+
ifisinstance(standbys,Iterable):
1056+
standbys=First(1,standbys)
1057+
else:
1058+
ifisinstance(standbys,Iterable):
1059+
standbys=u", ".join(
1060+
u"\"{}\"".format(r.name)forrinstandbys)
1061+
else:
1062+
raiseTestgresException("Feature isn't supported in "
1063+
"Postgres 9.5 and below")
10541064

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

‎tests/test_simple.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,12 @@ def test_replicate(self):
405405

406406
deftest_synchronous_replication(self):
407407
withget_new_node()asmaster:
408+
old_version=notpg_version_ge('9.6')
409+
408410
master.init(allow_streaming=True).start()
409-
master.append_conf('synchronous_commit = remote_apply')
411+
412+
ifnotold_version:
413+
master.append_conf('synchronous_commit = remote_apply')
410414

411415
# create standby
412416
withmaster.replicate()asstandby1,master.replicate()asstandby2:
@@ -424,16 +428,20 @@ def test_synchronous_replication(self):
424428
# set synchronous_standby_names
425429
master.set_synchronous_standbys([standby1,standby2])
426430
master.restart()
427-
master.safe_psql('create table abc(a int)')
428-
429-
# Create a large transaction that will take some time to apply
430-
# on standby to check that it applies synchronously
431-
# (If set synchronous_commit to 'on' or other lower level then
432-
# standby most likely won't catchup so fast and test will fail)
433-
master.safe_psql(
434-
'insert into abc select generate_series(1, 1000000)')
435-
res=standby1.safe_psql('select count(*) from abc')
436-
self.assertEqual(res,b'1000000\n')
431+
432+
# the following part of the test is only applicable to newer
433+
# versions of PostgresQL
434+
ifnotold_version:
435+
master.safe_psql('create table abc(a int)')
436+
437+
# Create a large transaction that will take some time to apply
438+
# on standby to check that it applies synchronously
439+
# (If set synchronous_commit to 'on' or other lower level then
440+
# standby most likely won't catchup so fast and test will fail)
441+
master.safe_psql(
442+
'insert into abc select generate_series(1, 1000000)')
443+
res=standby1.safe_psql('select count(*) from abc')
444+
self.assertEqual(res,b'1000000\n')
437445

438446
deftest_replication_slots(self):
439447
withget_new_node()asnode:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp