From d5b857da6914d9c58aaf04a7b8f17c3a35d0b560 Mon Sep 17 00:00:00 2001 From: Anastasiya Semenkevich Date: Thu, 29 Feb 2024 10:40:37 +0300 Subject: [PATCH] chore: remove attempts to connect to non-existing context and remove useless cycles --- test/e2e/driver/aut.py | 32 ++++++++++++-------------------- test/e2e/driver/context.py | 19 +++++++++---------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/test/e2e/driver/aut.py b/test/e2e/driver/aut.py index e3194425f9..6a9aa2af20 100644 --- a/test/e2e/driver/aut.py +++ b/test/e2e/driver/aut.py @@ -81,27 +81,19 @@ class AUT: self.pid = None @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) - 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) - 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 + 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 @@ -141,7 +133,7 @@ class AUT: return self @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) try: wait_for_port('localhost', self.port, timeout, retries) diff --git a/test/e2e/driver/context.py b/test/e2e/driver/context.py index 252f2ac424..5610022380 100644 --- a/test/e2e/driver/context.py +++ b/test/e2e/driver/context.py @@ -12,16 +12,15 @@ LOG = logging.getLogger(__name__) @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) - if context is not None: - LOG.info('AUT %s context found', aut_id) - return context - except RuntimeError: - time.sleep(10) - continue + LOG.info('Attaching to: %s', aut_id) + try: + context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port) + if context is not None: + LOG.info('AUT %s context found', aut_id) + return context + except RuntimeError as error: + LOG.error('AUT %s context has not been found', aut_id) + raise error @allure.step('Detaching')