Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5af8987

Browse files
committed
add max_attempts to cleanup()
1 parent 0fc86c9 commit 5af8987

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

testgres/testgres.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -706,19 +706,27 @@ def free_port(self):
706706
if self.should_free_port:
707707
release_port(self.port)
708708

709-
def cleanup(self):
709+
def cleanup(self, max_attempts=3):
710710
"""
711711
Stop node if needed and remove its data directory.
712712
713713
Returns:
714714
This instance of PostgresNode.
715715
"""
716716

717+
attempts = 0
718+
717719
# try stopping server
718-
try:
719-
self.stop()
720-
except:
721-
pass
720+
while attempts < max_attempts:
721+
try:
722+
self.stop()
723+
break # OK
724+
except ExecUtilException as e:
725+
pass # one more time
726+
except Exception as e:
727+
break # screw this
728+
729+
attempts += 1
722730

723731
# remove data directory
724732
shutil.rmtree(self.data_dir, ignore_errors=True)
@@ -845,8 +853,8 @@ def poll_query_until(self,
845853
raise_internal_error: mute InternalError?
846854
"""
847855

848-
attemps = 0
849-
while attemps < max_attempts:
856+
attempts = 0
857+
while attempts < max_attempts:
850858
try:
851859
res = self.execute(dbname=dbname,
852860
query=query,
@@ -877,7 +885,7 @@ def poll_query_until(self,
877885
raise e
878886

879887
time.sleep(sleep_time)
880-
attemps += 1
888+
attempts += 1
881889

882890
raise TimeoutException('Query timeout')
883891

0 commit comments

Comments
 (0)