fix(driver): drop retries from AUT launch method

The retries are just adding complexity and not helping.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2023-11-30 12:42:17 +01:00
parent 861af374cd
commit 9ae8173a0b
2 changed files with 35 additions and 39 deletions

View File

@ -1,7 +1,5 @@
import logging
from datetime import datetime
import allure import allure
import logging
import cv2 import cv2
import numpy as np import numpy as np
import squish import squish
@ -9,6 +7,8 @@ from PIL import ImageGrab
import configs import configs
import driver import driver
from os import path
from datetime import datetime
from configs.system import IS_LIN from configs.system import IS_LIN
from driver import context from driver import context
from driver.server import SquishServer from driver.server import SquishServer
@ -92,29 +92,25 @@ class AUT:
self._kill_process() self._kill_process()
@allure.step("Start application") @allure.step("Start application")
def launch(self, options='', attempt: int = 2) -> 'AUT': def launch(self) -> 'AUT':
self.options = options LOG.info('Launching AUT: %s', self.path)
try: self.port = local_system.find_free_port(configs.squish.AUT_PORT, 100)
self.port = local_system.find_free_port(configs.squish.AUT_PORT, 1000)
SquishServer().add_attachable_aut(self.aut_id, self.port) SquishServer().add_attachable_aut(self.aut_id, self.port)
command = [ command = [
configs.testpath.SQUISH_DIR / 'bin' / 'startaut', str(configs.testpath.SQUISH_DIR / 'bin/startaut'),
f'--port={self.port}', f'--port={self.port}',
f'"{self.path}"', str(self.path),
f'-d={self.app_data}', f'-d={self.app_data}',
f'--LOG_LEVEL={configs.testpath.LOG_LEVEL}', f'--LOG_LEVEL={configs.testpath.LOG_LEVEL}',
options
] ]
try:
self.pid = local_system.execute_with_log_files(command) self.pid = local_system.execute_with_log_files(command)
self.attach() self.attach()
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC) assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
return self return self
except (AssertionError, TypeError) as err: except Exception as err:
_logger.debug(err) LOG.error('Failed to start AUT: %s', err)
self.stop() self.stop()
if attempt:
return self.launch(options, attempt - 1)
else:
raise err raise err
@allure.step('Restart application') @allure.step('Restart application')

View File

@ -1,26 +1,26 @@
import allure import allure
import pytest import pytest
import logging
from driver.server import SquishServer from driver.server import SquishServer
LOG = logging.getLogger(__name__)
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def start_squish_server(): def start_squish_server():
squish_server = SquishServer() server = SquishServer()
squish_server.stop() server.stop()
attempt = 3
while True:
try: try:
squish_server.start() server.start()
squish_server.set_cursor_animation() server.wait()
squish_server.set_aut_timeout() yield server
break except Exception as err:
except AssertionError as err: LOG.error('Failed to start Squish Server: %s', error)
attempt -= 1
if not attempt:
pytest.exit(err) pytest.exit(err)
yield squish_server finally:
squish_server.stop() LOG.info('Stopping Squish Server...')
if squish_server.config.exists(): server.stop()
allure.attach.file(str(squish_server.config), 'Squish server config') if server.config.exists():
squish_server.config.unlink() allure.attach.file(str(server.config), 'Squish server config')
server.config.unlink()