chore: remove attempts to connect to non-existing context and remove useless cycles

This commit is contained in:
Anastasiya Semenkevich 2024-02-29 10:40:37 +03:00 committed by Anastasiya
parent 50cb471e3c
commit d5b857da69
2 changed files with 21 additions and 30 deletions

View File

@ -81,27 +81,19 @@ class AUT:
self.pid = None self.pid = None
@allure.step('Attach Squish to Test Application') @allure.step('Attach Squish to Test Application')
def attach(self): def attach(self, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
LOG.info('Attaching to AUT: localhost:%d', self.port) LOG.info('Attaching to AUT: localhost:%d', self.port)
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)
else:
if self.ctx is None:
for j in range(3):
try:
context.get_context(self.aut_id)
except AttributeError:
continue
squish.setApplicationContext(self.ctx) try:
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC) SquishServer().add_attachable_aut(self.aut_id, self.port)
except Exception as err: if self.ctx is None:
LOG.error('Failed to attach AUT: %s', err) self.ctx = context.get_context(self.aut_id)
self.stop() squish.setApplicationContext(self.ctx)
raise err 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!') LOG.info('Successfully attached AUT!')
return self return self
@ -141,7 +133,7 @@ class AUT:
return self return self
@allure.step('Waiting for port') @allure.step('Waiting for port')
def wait(self, timeout: int = 3, retries: int = 10): def wait(self, timeout: int = 1, retries: int = 10):
LOG.info('Waiting for AUT port localhost:%d...', self.port) LOG.info('Waiting for AUT port localhost:%d...', self.port)
try: try:
wait_for_port('localhost', self.port, timeout, retries) wait_for_port('localhost', self.port, timeout, retries)

View File

@ -12,16 +12,15 @@ LOG = logging.getLogger(__name__)
@allure.step('Get application context of "{0}"') @allure.step('Get application context of "{0}"')
def get_context(aut_id: str): def get_context(aut_id: str):
for i in range(10): LOG.info('Attaching to: %s', aut_id)
try: try:
LOG.debug('Attaching to: %s', aut_id) context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port) if context is not None:
if context is not None: LOG.info('AUT %s context found', aut_id)
LOG.info('AUT %s context found', aut_id) return context
return context except RuntimeError as error:
except RuntimeError: LOG.error('AUT %s context has not been found', aut_id)
time.sleep(10) raise error
continue
@allure.step('Detaching') @allure.step('Detaching')