chore; try to fix connection refused error
This commit is contained in:
parent
cbd27f87cd
commit
f868d2c1de
|
@ -76,25 +76,26 @@ class AUT:
|
||||||
|
|
||||||
def kill_process(self):
|
def kill_process(self):
|
||||||
if self.pid is None:
|
if self.pid is None:
|
||||||
LOG.warning('No PID availale for AUT.')
|
LOG.warning('No PID available for AUT.')
|
||||||
return
|
return
|
||||||
local_system.kill_process_with_retries(self.pid)
|
local_system.kill_process_with_retries(self.pid)
|
||||||
self.pid = None
|
self.pid = None
|
||||||
|
|
||||||
@allure.step('Attach Squish to Test Application')
|
@allure.step('Attach Squish to Test Application')
|
||||||
def attach(self, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
|
def attach(self):
|
||||||
LOG.info('Attaching to AUT: localhost:%d', self.port)
|
LOG.info('Attaching to AUT: localhost:%d', self.port)
|
||||||
try:
|
for i in range(3):
|
||||||
SquishServer().add_attachable_aut(self.aut_id, self.port)
|
try:
|
||||||
if self.ctx is None:
|
SquishServer().add_attachable_aut(self.aut_id, self.port)
|
||||||
self.ctx = context.attach(self.aut_id, timeout_sec)
|
if self.ctx is None:
|
||||||
squish.setApplicationContext(self.ctx)
|
self.ctx = context.get_context(self.aut_id)
|
||||||
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
|
squish.setApplicationContext(self.ctx)
|
||||||
except Exception as err:
|
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
|
||||||
LOG.error('Failed to attach AUT: %s', err)
|
except Exception as err:
|
||||||
self.stop()
|
LOG.error('Failed to attach AUT: %s', err)
|
||||||
raise err
|
self.stop()
|
||||||
LOG.info('Succesfully attached AUT!')
|
raise err
|
||||||
|
LOG.info('Successfully attached AUT!')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@allure.step('Start AUT')
|
@allure.step('Start AUT')
|
||||||
|
@ -120,7 +121,7 @@ class AUT:
|
||||||
|
|
||||||
@allure.step('Close application')
|
@allure.step('Close application')
|
||||||
def stop(self):
|
def stop(self):
|
||||||
LOG.info('Stoping AUT: %s', self.path)
|
LOG.info('Stopping AUT: %s', self.path)
|
||||||
self.detach_context()
|
self.detach_context()
|
||||||
self.kill_process()
|
self.kill_process()
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ class AUT:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@allure.step('Waiting for port')
|
@allure.step('Waiting for port')
|
||||||
def wait(self, timeout: int = 1, retries: int = 10):
|
def wait(self, timeout: int = 3, retries: int = 10):
|
||||||
LOG.info('Waiting for AUT port localhost:%d...', self.port)
|
LOG.info('Waiting for AUT port localhost:%d...', self.port)
|
||||||
try:
|
try:
|
||||||
wait_for_port('localhost', self.port, timeout, retries)
|
wait_for_port('localhost', self.port, timeout, retries)
|
||||||
|
|
|
@ -10,18 +10,18 @@ from driver.server import SquishServer
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@allure.step('Attaching to "{0}"')
|
@allure.step('Get application context of "{0}"')
|
||||||
def attach(aut_id: str, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
|
def get_context(aut_id: str):
|
||||||
started_at = time.monotonic()
|
for i in range(10):
|
||||||
LOG.debug('Attaching to: %s', aut_id)
|
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
|
LOG.debug('Attaching to: %s', aut_id)
|
||||||
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
|
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
|
||||||
LOG.info('AUT %s attached', aut_id)
|
if context is not None:
|
||||||
return context
|
LOG.info('AUT %s context found', aut_id)
|
||||||
except RuntimeError as err:
|
return context
|
||||||
time.sleep(1)
|
except RuntimeError:
|
||||||
assert time.monotonic() - started_at < timeout_sec, str(err)
|
time.sleep(10)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
@allure.step('Detaching')
|
@allure.step('Detaching')
|
||||||
|
|
Loading…
Reference in New Issue