Skip to content

Commit ba7a630

Browse files
committed
feat: add fail_safe to Run.command()
1 parent 7c60aa9 commit ba7a630

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

core/utils/device/adb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
# noinspection PyShadowingBuiltins
1515
class Adb(object):
1616
@staticmethod
17-
def __run_adb_command(command, id=None, wait=True, log_level=logging.DEBUG):
17+
def __run_adb_command(command, id=None, wait=True, timeout=60, fail_safe=False, log_level=logging.DEBUG):
1818
if id is None:
1919
command = '{0} {1}'.format(ADB_PATH, command)
2020
else:
2121
command = '{0} -s {1} {2}'.format(ADB_PATH, id, command)
22-
return Run.command(cmd=command, wait=wait, log_level=log_level)
22+
return Run.command(cmd=command, wait=wait, timeout=timeout, fail_safe=fail_safe, log_level=log_level)
2323

2424
@staticmethod
2525
def __get_ids(include_emulator=False):
@@ -61,7 +61,7 @@ def is_running(id):
6161
command = "shell dumpsys window windows | findstr mFocusedApp"
6262
else:
6363
command = "shell dumpsys window windows | grep -E 'mFocusedApp'"
64-
result = Adb.__run_adb_command(command=command, id=id)
64+
result = Adb.__run_adb_command(command=command, id=id, timeout=10, fail_safe=True)
6565
if 'ActivityRecord' in result.output:
6666
return True
6767
else:

core/utils/process.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class Run(object):
1919
@staticmethod
20-
def command(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, register_for_cleanup=True, timeout=600,
20+
def command(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, fail_safe=False, register_for_cleanup=True, timeout=600,
2121
log_level=logging.DEBUG):
2222
# Init result values
2323
log_file = None
@@ -51,7 +51,10 @@ def command(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, register_for_cleanup=Tru
5151
p.wait(timeout=timeout)
5252
except psutil.TimeoutExpired:
5353
p.kill()
54-
raise
54+
if not fail_safe:
55+
raise
56+
else:
57+
Log.error('Command reached timeout limit: {0}'.format(cmd))
5558
out, err = process.communicate()
5659
output = (str(out) + os.linesep + str(err)).rstrip()
5760
complete = True

0 commit comments

Comments
 (0)