Skip to content

Commit d01804b

Browse files
author
v.shepard
committed
PBCKP-137 update node
1 parent 0d62e0e commit d01804b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

testgres/node.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
InternalError = pglib.InternalError
106106
ProgrammingError = pglib.ProgrammingError
107107
OperationalError = pglib.OperationalError
108-
DatabaseError = pglib.DatabaseError
109108

110109

111110
class ProcessProxy(object):
@@ -653,7 +652,7 @@ def get_control_data(self):
653652

654653
return out_dict
655654

656-
def slow_start(self, replica=False, dbname='template1', username='dev'):
655+
def slow_start(self, replica=False, dbname='template1', username=default_username()):
657656
"""
658657
Starts the PostgreSQL instance and then polls the instance
659658
until it reaches the expected state (primary or replica). The state is checked
@@ -673,14 +672,12 @@ def slow_start(self, replica=False, dbname='template1', username='dev'):
673672
query = 'SELECT not pg_is_in_recovery()'
674673
# Call poll_query_until until the expected value is returned
675674
self.poll_query_until(query=query,
676-
expected=False,
677675
dbname=dbname,
678676
username=username,
679677
suppress={InternalError,
680678
QueryException,
681679
ProgrammingError,
682-
OperationalError,
683-
DatabaseError})
680+
OperationalError})
684681

685682
def start(self, params=[], wait=True):
686683
"""
@@ -970,7 +967,7 @@ def psql(self,
970967
return process.returncode, out, err
971968

972969
@method_decorator(positional_args_hack(['dbname', 'query']))
973-
def safe_psql(self, query=None, **kwargs):
970+
def safe_psql(self, query=None, expect_error=False, **kwargs):
974971
"""
975972
Execute a query using psql.
976973
@@ -980,6 +977,8 @@ def safe_psql(self, query=None, **kwargs):
980977
dbname: database name to connect to.
981978
username: database user name.
982979
input: raw input to be passed.
980+
expect_error: if True - fail if we didn't get ret
981+
if False - fail if we got ret
983982
984983
**kwargs are passed to psql().
985984
@@ -992,7 +991,12 @@ def safe_psql(self, query=None, **kwargs):
992991

993992
ret, out, err = self.psql(query=query, **kwargs)
994993
if ret:
995-
raise QueryException((err or b'').decode('utf-8'), query)
994+
if expect_error:
995+
out = (err or b'').decode('utf-8')
996+
else:
997+
raise QueryException((err or b'').decode('utf-8'), query)
998+
elif expect_error:
999+
assert False, f"Exception was expected, but query finished successfully: `{query}` "
9961000

9971001
return out
9981002

@@ -1139,7 +1143,7 @@ def poll_query_until(self,
11391143
elif expected is None:
11401144
return # done
11411145

1142-
except tuple(suppress or []):
1146+
except tuple(suppress or []) as e:
11431147
pass # we're suppressing them
11441148

11451149
time.sleep(sleep_time)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy