chore: squeeze 2 kill methods to 1
This commit is contained in:
parent
19f6cf9e11
commit
9ce23fe556
|
@ -73,13 +73,6 @@ class AUT:
|
|||
squish.currentApplicationContext().detach()
|
||||
self.ctx = None
|
||||
|
||||
def kill_process(self):
|
||||
if self.pid is None:
|
||||
LOG.warning('No PID available for AUT.')
|
||||
return
|
||||
local_system.kill_process_with_retries(self.pid)
|
||||
self.pid = None
|
||||
|
||||
@allure.step('Attach Squish to Test Application')
|
||||
def attach(self, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
|
||||
LOG.info('Attaching to AUT: localhost:%d', self.port)
|
||||
|
@ -123,7 +116,7 @@ class AUT:
|
|||
def stop(self):
|
||||
LOG.info('Stopping AUT: %s', self.path)
|
||||
self.detach_context()
|
||||
self.kill_process()
|
||||
local_system.kill_process(self.pid)
|
||||
|
||||
@allure.step("Start and attach AUT")
|
||||
def launch(self) -> 'AUT':
|
||||
|
|
|
@ -42,7 +42,7 @@ class SquishServer:
|
|||
if cls.pid is None:
|
||||
return
|
||||
LOG.info('Stopping Squish Server with PID: %d', cls.pid)
|
||||
local_system.kill_process_with_retries(cls.pid)
|
||||
local_system.kill_process(cls.pid)
|
||||
cls.pid = None
|
||||
cls.port = None
|
||||
|
||||
|
|
|
@ -36,34 +36,19 @@ def find_free_port(start: int, step: int):
|
|||
def kill_process(pid, sig: signal.Signals = signal.SIGKILL):
|
||||
LOG.debug('Sending %s to %d process', sig.name, pid)
|
||||
try:
|
||||
os.kill(pid, sig)
|
||||
p = psutil.Process(pid)
|
||||
|
||||
except ProcessLookupError as err:
|
||||
LOG.error('Failed to find process %d: %s', pid, err)
|
||||
raise err
|
||||
|
||||
|
||||
@allure.step('Kill process with retries')
|
||||
def kill_process_with_retries(pid, sig: signal.Signals = signal.SIGKILL, attempts: int = 3):
|
||||
LOG.debug('Killing process: %d', pid)
|
||||
try:
|
||||
p = psutil.Process(pid)
|
||||
except psutil.NoSuchProcess:
|
||||
LOG.warning('Process %d already gone.', pid)
|
||||
return
|
||||
|
||||
p.send_signal(sig)
|
||||
|
||||
while attempts > 0:
|
||||
attempts -= 1
|
||||
for i in range(2):
|
||||
try:
|
||||
LOG.warning('Waiting for process to exit: %d', pid)
|
||||
p.wait()
|
||||
except TimeoutError as err:
|
||||
p.kill()
|
||||
else:
|
||||
return
|
||||
|
||||
raise RuntimeError('Failed to kill process: %d' % pid)
|
||||
if not p.is_running():
|
||||
break
|
||||
except RuntimeError:
|
||||
raise ('Failed to kill process: %d' % pid)
|
||||
|
||||
|
||||
@allure.step('System execute command')
|
||||
|
|
Loading…
Reference in New Issue