Content-Length: 3787 | pFad | http://github.com/postgrespro/testgres/pull/145.patch
thub.com
From e0d7eacf2632aef4957ee03378673e7a2917e61b Mon Sep 17 00:00:00 2001
From: vshepard
Date: Tue, 17 Sep 2024 08:51:20 +0200
Subject: [PATCH] Fix node.py: try_shutdown and cleanup
---
testgres/node.py | 59 ++++++++++++++++++++++++------------------------
1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/testgres/node.py b/testgres/node.py
index 1404f9cc..b9bf9896 100644
--- a/testgres/node.py
+++ b/testgres/node.py
@@ -334,37 +334,38 @@ def _try_shutdown(self, max_attempts, with_force=False):
attempts = 0
node_pid = self.pid
- # try stopping server N times
- while attempts < max_attempts:
- try:
- self.stop()
- break # OK
- except ExecUtilException:
- pass # one more time
- except Exception:
- eprint('cannot stop node {}'.format(self.name))
- break
-
- attempts += 1
-
- # If force stopping is enabled and PID is valid
- if with_force and node_pid != 0:
- # If we couldn't stop the node
- p_status_output = self.os_ops.exec_command(cmd=f'ps -p {node_pid}', shell=True).decode('utf-8')
- if self.status() != NodeStatus.Stopped and p_status_output and str(node_pid) in p_status_output:
+ if node_pid > 0:
+ # try stopping server N times
+ while attempts < max_attempts:
try:
- eprint(f'Force stopping node {self.name} with PID {node_pid}')
- self.os_ops.kill(node_pid, signal.SIGKILL, expect_error=False)
+ self.stop()
+ break # OK
+ except ExecUtilException:
+ pass # one more time
except Exception:
- # The node has already stopped
- pass
-
- # Check that node stopped - print only column pid without headers
- p_status_output = self.os_ops.exec_command(f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8')
- if p_status_output and str(node_pid) in p_status_output:
- eprint(f'Failed to stop node {self.name}.')
- else:
- eprint(f'Node {self.name} has been stopped successfully.')
+ eprint('cannot stop node {}'.format(self.name))
+ break
+
+ attempts += 1
+
+ # If force stopping is enabled and PID is valid
+ if with_force and node_pid != 0:
+ # If we couldn't stop the node
+ p_status_output = self.os_ops.exec_command(cmd=f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8')
+ if self.status() != NodeStatus.Stopped and p_status_output and str(node_pid) in p_status_output:
+ try:
+ eprint(f'Force stopping node {self.name} with PID {node_pid}')
+ self.os_ops.kill(node_pid, signal.SIGKILL, expect_error=False)
+ except Exception:
+ # The node has already stopped
+ pass
+
+ # Check that node stopped - print only column pid without headers
+ p_status_output = self.os_ops.exec_command(f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8')
+ if p_status_output and str(node_pid) in p_status_output:
+ eprint(f'Failed to stop node {self.name}.')
+ else:
+ eprint(f'Node {self.name} has been stopped successfully.')
def _assign_master(self, master):
"""NOTE: this is a private method!"""
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/postgrespro/testgres/pull/145.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy