Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 6643384

Browse files
committed
chore: remove attempts to connect to non-existing context and remove useless cycles
1 parent 568f074 commit 6643384

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

driver/aut.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,19 @@ def kill_process(self):
8181
self.pid = None
8282

8383
@allure.step('Attach Squish to Test Application')
84-
def attach(self):
84+
def attach(self, timeout_sec: int = configs.timeouts.PROCESS_TIMEOUT_SEC):
8585
LOG.info('Attaching to AUT: localhost:%d', self.port)
86-
for i in range(3):
87-
try:
88-
SquishServer().add_attachable_aut(self.aut_id, self.port)
89-
if self.ctx is None:
90-
self.ctx = context.get_context(self.aut_id)
91-
else:
92-
if self.ctx is None:
93-
for j in range(3):
94-
try:
95-
context.get_context(self.aut_id)
96-
except AttributeError:
97-
continue
98-
99-
squish.setApplicationContext(self.ctx)
100-
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
101-
except Exception as err:
102-
LOG.error('Failed to attach AUT: %s', err)
103-
self.stop()
104-
raise err
86+
87+
try:
88+
SquishServer().add_attachable_aut(self.aut_id, self.port)
89+
if self.ctx is None:
90+
self.ctx = context.get_context(self.aut_id)
91+
squish.setApplicationContext(self.ctx)
92+
assert squish.waitFor(lambda: self.ctx.isRunning, configs.timeouts.PROCESS_TIMEOUT_SEC)
93+
except Exception as err:
94+
LOG.error('Failed to attach AUT: %s', err)
95+
self.stop()
96+
raise err
10597
LOG.info('Successfully attached AUT!')
10698
return self
10799

@@ -141,7 +133,7 @@ def launch(self) -> 'AUT':
141133
return self
142134

143135
@allure.step('Waiting for port')
144-
def wait(self, timeout: int = 3, retries: int = 10):
136+
def wait(self, timeout: int = 1, retries: int = 10):
145137
LOG.info('Waiting for AUT port localhost:%d...', self.port)
146138
try:
147139
wait_for_port('localhost', self.port, timeout, retries)

driver/context.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
@allure.step('Get application context of "{0}"')
1414
def get_context(aut_id: str):
15-
for i in range(10):
16-
try:
17-
LOG.debug('Attaching to: %s', aut_id)
18-
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
19-
if context is not None:
20-
LOG.info('AUT %s context found', aut_id)
21-
return context
22-
except RuntimeError:
23-
time.sleep(10)
24-
continue
15+
LOG.info('Attaching to: %s', aut_id)
16+
try:
17+
context = squish.attachToApplication(aut_id, SquishServer().host, SquishServer().port)
18+
if context is not None:
19+
LOG.info('AUT %s context found', aut_id)
20+
return context
21+
except RuntimeError as error:
22+
LOG.error('AUT %s context has not been found', aut_id)
23+
raise error
2524

2625

2726
@allure.step('Detaching')

0 commit comments

Comments
 (0)