From 9ae8173a0b1cd3e7b1d47df92a30bb4841408a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 30 Nov 2023 12:42:17 +0100 Subject: [PATCH] fix(driver): drop retries from AUT launch method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The retries are just adding complexity and not helping. Signed-off-by: Jakub SokoĊ‚owski --- test/e2e/driver/aut.py | 38 +++++++++++++++++-------------------- test/e2e/fixtures/squish.py | 36 +++++++++++++++++------------------ 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/test/e2e/driver/aut.py b/test/e2e/driver/aut.py index 89f81d3c59..0b2e7bb1df 100644 --- a/test/e2e/driver/aut.py +++ b/test/e2e/driver/aut.py @@ -1,7 +1,5 @@ -import logging -from datetime import datetime - import allure +import logging import cv2 import numpy as np import squish @@ -9,6 +7,8 @@ from PIL import ImageGrab import configs import driver +from os import path +from datetime import datetime from configs.system import IS_LIN from driver import context from driver.server import SquishServer @@ -92,30 +92,26 @@ class AUT: self._kill_process() @allure.step("Start application") - def launch(self, options='', attempt: int = 2) -> 'AUT': - self.options = options + def launch(self) -> 'AUT': + LOG.info('Launching AUT: %s', self.path) + self.port = local_system.find_free_port(configs.squish.AUT_PORT, 100) + SquishServer().add_attachable_aut(self.aut_id, self.port) + command = [ + str(configs.testpath.SQUISH_DIR / 'bin/startaut'), + f'--port={self.port}', + str(self.path), + f'-d={self.app_data}', + f'--LOG_LEVEL={configs.testpath.LOG_LEVEL}', + ] try: - self.port = local_system.find_free_port(configs.squish.AUT_PORT, 1000) - SquishServer().add_attachable_aut(self.aut_id, self.port) - command = [ - configs.testpath.SQUISH_DIR / 'bin' / 'startaut', - f'--port={self.port}', - f'"{self.path}"', - f'-d={self.app_data}', - f'--LOG_LEVEL={configs.testpath.LOG_LEVEL}', - options - ] self.pid = local_system.execute_with_log_files(command) self.attach() assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC) return self - except (AssertionError, TypeError) as err: - _logger.debug(err) + except Exception as err: + LOG.error('Failed to start AUT: %s', err) self.stop() - if attempt: - return self.launch(options, attempt - 1) - else: - raise err + raise err @allure.step('Restart application') def restart(self): diff --git a/test/e2e/fixtures/squish.py b/test/e2e/fixtures/squish.py index 810c4b40f5..970b7a1475 100644 --- a/test/e2e/fixtures/squish.py +++ b/test/e2e/fixtures/squish.py @@ -1,26 +1,26 @@ import allure import pytest +import logging from driver.server import SquishServer +LOG = logging.getLogger(__name__) + @pytest.fixture(scope='session') def start_squish_server(): - squish_server = SquishServer() - squish_server.stop() - attempt = 3 - while True: - try: - squish_server.start() - squish_server.set_cursor_animation() - squish_server.set_aut_timeout() - break - except AssertionError as err: - attempt -= 1 - if not attempt: - pytest.exit(err) - yield squish_server - squish_server.stop() - if squish_server.config.exists(): - allure.attach.file(str(squish_server.config), 'Squish server config') - squish_server.config.unlink() + server = SquishServer() + server.stop() + try: + server.start() + server.wait() + yield server + except Exception as err: + LOG.error('Failed to start Squish Server: %s', error) + pytest.exit(err) + finally: + LOG.info('Stopping Squish Server...') + server.stop() + if server.config.exists(): + allure.attach.file(str(server.config), 'Squish server config') + server.config.unlink()