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 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):

View File

@ -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()