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

add 'suppress' to PostgresNode.poll_query_until() to mute exceptions#51

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
4 changes: 3 additions & 1 deletiontestgres/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,10 @@

from .connection import \
NodeConnection, \
DatabaseError, \
InternalError, \
ProgrammingError
ProgrammingError, \
OperationalError

from .exceptions import *
from .enums import *
Expand Down
4 changes: 3 additions & 1 deletiontestgres/connection.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,9 +17,11 @@

from .exceptions import QueryException

# export these exceptions
# export some exceptions
DatabaseError = pglib.DatabaseError
InternalError = pglib.InternalError
ProgrammingError = pglib.ProgrammingError
OperationalError = pglib.OperationalError


class NodeConnection(object):
Expand Down
42 changes: 17 additions & 25 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,10 +19,7 @@

from .config import testgres_config

from .connection import \
NodeConnection, \
InternalError, \
ProgrammingError
from .connection import NodeConnection

from .consts import \
DATA_DIR, \
Expand DownExpand Up@@ -531,10 +528,10 @@ def append_conf(self, line='', filename=PG_CONF_FILE, **kwargs):
This instance of :class:`.PostgresNode`.

Examples:
append_conf(fsync=False)
append_conf('log_connections = yes')
append_conf(random_page_cost=1.5, fsync=True, ...)
append_conf('postgresql.conf', 'synchronous_commit = off')
>>>append_conf(fsync=False)
>>>append_conf('log_connections = yes')
>>>append_conf(random_page_cost=1.5, fsync=True, ...)
>>>append_conf('postgresql.conf', 'synchronous_commit = off')
"""

lines = [line]
Expand DownExpand Up@@ -970,8 +967,7 @@ def poll_query_until(self,
sleep_time=1,
expected=True,
commit=True,
raise_programming_error=True,
raise_internal_error=True):
suppress=None):
"""
Run a query once per second until it returns 'expected'.
Query should return a single value (1 row, 1 column).
Expand All@@ -984,13 +980,13 @@ def poll_query_until(self,
sleep_time: how much should we sleep after a failure?
expected: what should be returned to break the cycle?
commit: should (possible) changes be committed?
raise_programming_error: enable ProgrammingError?
raise_internal_error: enable InternalError?
suppress: a collection of exceptions to be suppressed.

Examples:
poll_query_until('select true')
poll_query_until('postgres', "select now() > '01.01.2018'")
poll_query_until('select false', expected=True, max_attempts=4)
>>> poll_query_until('select true')
>>> poll_query_until('postgres', "select now() > '01.01.2018'")
>>> poll_query_until('select false', expected=True, max_attempts=4)
>>> poll_query_until('select 1', suppress={testgres.OperationalError})
"""

# sanity checks
Expand DownExpand Up@@ -1022,13 +1018,8 @@ def poll_query_until(self,
elif expected is None:
return # done

except ProgrammingError as e:
if raise_programming_error:
raise e

except InternalError as e:
if raise_internal_error:
raise e
except tuple(suppress or []):
pass # we're suppressing them

time.sleep(sleep_time)
attempts += 1
Expand DownExpand Up@@ -1219,13 +1210,14 @@ def pgbench_run(self, dbname=None, username=None, options=[], **kwargs):
options: additional options for pgbench (list).

**kwargs: named options for pgbench.
Examples:
pgbench_run(initialize=True, scale=2)
pgbench_run(time=10)
Run pgbench --help to learn more.

Returns:
Stdout produced by pgbench.

Examples:
>>> pgbench_run(initialize=True, scale=2)
>>> pgbench_run(time=10)
"""

# Set default arguments
Expand Down
2 changes: 1 addition & 1 deletiontests/test_simple.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -625,7 +625,7 @@ def test_poll_query_until(self):
query='dummy2',
max_attempts=3,
sleep_time=0.01,
raise_programming_error=False)
suppress={testgres.ProgrammingError})

# check 1 arg, ok
node.poll_query_until('select true')
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp