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

Commite78ddd9

Browse files
committed
add 'suppress' to PostgresNode.poll_query_until() to mute exceptions
1 parent80a3e55 commite78ddd9

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

‎testgres/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
from .connectionimport \
1212
NodeConnection, \
13+
DatabaseError, \
1314
InternalError, \
14-
ProgrammingError
15+
ProgrammingError, \
16+
OperationalError
1517

1618
from .exceptionsimport*
1719
from .enumsimport*

‎testgres/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
from .exceptionsimportQueryException
1919

20-
# export these exceptions
20+
# export some exceptions
21+
DatabaseError=pglib.DatabaseError
2122
InternalError=pglib.InternalError
2223
ProgrammingError=pglib.ProgrammingError
24+
OperationalError=pglib.OperationalError
2325

2426

2527
classNodeConnection(object):

‎testgres/node.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
from .configimporttestgres_config
2121

22-
from .connectionimport \
23-
NodeConnection, \
24-
InternalError, \
25-
ProgrammingError
22+
from .connectionimportNodeConnection
2623

2724
from .constsimport \
2825
DATA_DIR, \
@@ -531,10 +528,10 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
531528
This instance of :class:`.PostgresNode`.
532529
533530
Examples:
534-
append_conf(fsync=False)
535-
append_conf('log_connections = yes')
536-
append_conf(random_page_cost=1.5, fsync=True, ...)
537-
append_conf('postgresql.conf', 'synchronous_commit = off')
531+
>>>append_conf(fsync=False)
532+
>>>append_conf('log_connections = yes')
533+
>>>append_conf(random_page_cost=1.5, fsync=True, ...)
534+
>>>append_conf('postgresql.conf', 'synchronous_commit = off')
538535
"""
539536

540537
lines= [line]
@@ -970,8 +967,7 @@ def poll_query_until(self,
970967
sleep_time=1,
971968
expected=True,
972969
commit=True,
973-
raise_programming_error=True,
974-
raise_internal_error=True):
970+
suppress=None):
975971
"""
976972
Run a query once per second until it returns 'expected'.
977973
Query should return a single value (1 row, 1 column).
@@ -984,13 +980,13 @@ def poll_query_until(self,
984980
sleep_time: how much should we sleep after a failure?
985981
expected: what should be returned to break the cycle?
986982
commit: should (possible) changes be committed?
987-
raise_programming_error: enable ProgrammingError?
988-
raise_internal_error: enable InternalError?
983+
suppress: a collection of exceptions to be suppressed.
989984
990985
Examples:
991-
poll_query_until('select true')
992-
poll_query_until('postgres', "select now() > '01.01.2018'")
993-
poll_query_until('select false', expected=True, max_attempts=4)
986+
>>> poll_query_until('select true')
987+
>>> poll_query_until('postgres', "select now() > '01.01.2018'")
988+
>>> poll_query_until('select false', expected=True, max_attempts=4)
989+
>>> poll_query_until('select 1', suppress={testgres.OperationalError})
994990
"""
995991

996992
# sanity checks
@@ -1022,13 +1018,8 @@ def poll_query_until(self,
10221018
elifexpectedisNone:
10231019
return# done
10241020

1025-
exceptProgrammingErrorase:
1026-
ifraise_programming_error:
1027-
raisee
1028-
1029-
exceptInternalErrorase:
1030-
ifraise_internal_error:
1031-
raisee
1021+
excepttuple(suppressor []):
1022+
pass# we're suppressing them
10321023

10331024
time.sleep(sleep_time)
10341025
attempts+=1
@@ -1219,13 +1210,14 @@ def pgbench_run(self, dbname=None, username=None, options=[], **kwargs):
12191210
options: additional options for pgbench (list).
12201211
12211212
**kwargs: named options for pgbench.
1222-
Examples:
1223-
pgbench_run(initialize=True, scale=2)
1224-
pgbench_run(time=10)
12251213
Run pgbench --help to learn more.
12261214
12271215
Returns:
12281216
Stdout produced by pgbench.
1217+
1218+
Examples:
1219+
>>> pgbench_run(initialize=True, scale=2)
1220+
>>> pgbench_run(time=10)
12291221
"""
12301222

12311223
# Set default arguments

‎tests/test_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def test_poll_query_until(self):
625625
query='dummy2',
626626
max_attempts=3,
627627
sleep_time=0.01,
628-
raise_programming_error=False)
628+
suppress={testgres.ProgrammingError})
629629

630630
# check 1 arg, ok
631631
node.poll_query_until('select true')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp