Skip to content

Commit 0847cf2

Browse files
authored
Merge pull request #51 from funbringer/poll_query_until_suppress
add 'suppress' to PostgresNode.poll_query_until() to mute exceptions
2 parents c187ccb + e78ddd9 commit 0847cf2

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

Diff for: testgres/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

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

1618
from .exceptions import *
1719
from .enums import *

Diff for: testgres/connection.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
from .exceptions import QueryException
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
class NodeConnection(object):

Diff for: testgres/node.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
from .config import testgres_config
2121

22-
from .connection import \
23-
NodeConnection, \
24-
InternalError, \
25-
ProgrammingError
22+
from .connection import NodeConnection
2623

2724
from .consts import \
2825
DATA_DIR, \
@@ -541,10 +538,10 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
541538
This instance of :class:`.PostgresNode`.
542539
543540
Examples:
544-
append_conf(fsync=False)
545-
append_conf('log_connections = yes')
546-
append_conf(random_page_cost=1.5, fsync=True, ...)
547-
append_conf('postgresql.conf', 'synchronous_commit = off')
541+
>>> append_conf(fsync=False)
542+
>>> append_conf('log_connections = yes')
543+
>>> append_conf(random_page_cost=1.5, fsync=True, ...)
544+
>>> append_conf('postgresql.conf', 'synchronous_commit = off')
548545
"""
549546

550547
lines = [line]
@@ -980,8 +977,7 @@ def poll_query_until(self,
980977
sleep_time=1,
981978
expected=True,
982979
commit=True,
983-
raise_programming_error=True,
984-
raise_internal_error=True):
980+
suppress=None):
985981
"""
986982
Run a query once per second until it returns 'expected'.
987983
Query should return a single value (1 row, 1 column).
@@ -994,13 +990,13 @@ def poll_query_until(self,
994990
sleep_time: how much should we sleep after a failure?
995991
expected: what should be returned to break the cycle?
996992
commit: should (possible) changes be committed?
997-
raise_programming_error: enable ProgrammingError?
998-
raise_internal_error: enable InternalError?
993+
suppress: a collection of exceptions to be suppressed.
999994
1000995
Examples:
1001-
poll_query_until('select true')
1002-
poll_query_until('postgres', "select now() > '01.01.2018'")
1003-
poll_query_until('select false', expected=True, max_attempts=4)
996+
>>> poll_query_until('select true')
997+
>>> poll_query_until('postgres', "select now() > '01.01.2018'")
998+
>>> poll_query_until('select false', expected=True, max_attempts=4)
999+
>>> poll_query_until('select 1', suppress={testgres.OperationalError})
10041000
"""
10051001

10061002
# sanity checks
@@ -1032,13 +1028,8 @@ def poll_query_until(self,
10321028
elif expected is None:
10331029
return # done
10341030

1035-
except ProgrammingError as e:
1036-
if raise_programming_error:
1037-
raise e
1038-
1039-
except InternalError as e:
1040-
if raise_internal_error:
1041-
raise e
1031+
except tuple(suppress or []):
1032+
pass # we're suppressing them
10421033

10431034
time.sleep(sleep_time)
10441035
attempts += 1
@@ -1229,13 +1220,14 @@ def pgbench_run(self, dbname=None, username=None, options=[], **kwargs):
12291220
options: additional options for pgbench (list).
12301221
12311222
**kwargs: named options for pgbench.
1232-
Examples:
1233-
pgbench_run(initialize=True, scale=2)
1234-
pgbench_run(time=10)
12351223
Run pgbench --help to learn more.
12361224
12371225
Returns:
12381226
Stdout produced by pgbench.
1227+
1228+
Examples:
1229+
>>> pgbench_run(initialize=True, scale=2)
1230+
>>> pgbench_run(time=10)
12391231
"""
12401232

12411233
# Set default arguments

Diff for: tests/test_simple.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def test_poll_query_until(self):
626626
query='dummy2',
627627
max_attempts=3,
628628
sleep_time=0.01,
629-
raise_programming_error=False)
629+
suppress={testgres.ProgrammingError})
630630

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

0 commit comments

Comments
 (0)