chore; try to fix connection refused error

This commit is contained in:
Anastasiya Semenkevich 2024-02-09 17:30:35 +03:00 committed by Anastasiya
parent cbd27f87cd
commit f868d2c1de
2 changed files with 26 additions and 25 deletions

View File

@ -76,25 +76,26 @@ class AUT:
def kill_process(self):
if self.pid is None:
LOG.warning('No PID availale for AUT.')
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):
def attach(self):
LOG.info('Attaching to AUT: localhost:%d', self.port)
try:
SquishServer().add_attachable_aut(self.aut_id, self.port)
if self.ctx is None:
self.ctx = context.attach(self.aut_id, timeout_sec)
squish.setApplicationContext(self.ctx)
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
except Exception as err:
LOG.error('Failed to attach AUT: %s', err)
self.stop()
raise err
LOG.info('Succesfully attached AUT!')
for i in range(3):
try:
SquishServer().add_attachable_aut(self.aut_id, self.port)
if self.ctx is None:
self.ctx = context.get_context(self.aut_id)
squish.setApplicationContext(self.ctx)
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
except Exception as err:
LOG.error('Failed to attach AUT: %s', err)
self.stop()
raise err
LOG.info('Successfully attached AUT!')
return self
@allure.step('Start AUT')
@ -120,7 +121,7 @@ class AUT:
@allure.step('Close application')
def stop(self):
LOG.info('Stoping AUT: %s', self.path)
LOG.info('Stopping AUT: %s', self.path)
self.detach_context()
self.kill_process()
@ -132,7 +133,7 @@ class AUT:
return self
@allure.step('Waiting for port')
def wait(self, timeout: int = 1, retries: int = 10):
def wait(self, timeout: int = 3, retries: int = 10):
LOG.info('Waiting for AUT port localhost:%d...', self.port)
try:
wait_for_port('localhost', self.port, timeout, retries)

View File

@ -10,18 +10,18 @@ from driver.server import SquishServer
LOG = logging.getLogger(__name__)
@allure.step('Attaching to "{0}"')
def attach(aut_id: str, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
started_at = time.monotonic()
LOG.debug('Attaching to: %s', aut_id)
while True:
@allure.step('Get application context of "{0}"')
def get_context(aut_id: str):
for i in range(10):
try:
LOG.debug('Attaching to: %s', aut_id)
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
LOG.info('AUT %s attached', aut_id)
return context
except RuntimeError as err:
time.sleep(1)
assert time.monotonic() - started_at < timeout_sec, str(err)
if context is not None:
LOG.info('AUT %s context found', aut_id)
return context
except RuntimeError:
time.sleep(10)
continue
@allure.step('Detaching')