2023-08-04 18:27:03 +00:00
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import squish
|
|
|
|
|
|
|
|
import configs
|
2023-10-23 11:53:11 +00:00
|
|
|
from driver.server import SquishServer
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@allure.step('Attaching to "{0}"')
|
2023-09-28 12:44:13 +00:00
|
|
|
def attach(aut_id: str, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
|
2023-08-04 18:27:03 +00:00
|
|
|
started_at = time.monotonic()
|
2023-09-28 12:44:13 +00:00
|
|
|
_logger.debug(f'Attaching to {aut_id}')
|
2023-08-04 18:27:03 +00:00
|
|
|
while True:
|
|
|
|
try:
|
2023-10-23 11:53:11 +00:00
|
|
|
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
|
2023-09-28 12:44:13 +00:00
|
|
|
_logger.info(f'AUT: {aut_id} attached')
|
2023-08-04 18:27:03 +00:00
|
|
|
return context
|
|
|
|
except RuntimeError as err:
|
|
|
|
time.sleep(1)
|
2023-10-27 11:44:45 +00:00
|
|
|
assert time.monotonic() - started_at < timeout_sec, str(err)
|
2023-08-04 18:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@allure.step('Detaching')
|
|
|
|
def detach():
|
|
|
|
for ctx in squish.applicationContextList():
|
|
|
|
ctx.detach()
|
|
|
|
assert squish.waitFor(lambda: not ctx.isRunning, configs.timeouts.APP_LOAD_TIMEOUT_MSEC)
|
|
|
|
_logger.info(f'All AUTs detached')
|