aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantofara <48907599+antofara@users.noreply.github.com>2023-02-02 21:03:12 +0100
committerGitHub <noreply@github.com>2023-02-02 12:03:12 -0800
commit927dd31baf4f778b4bdbfa38f1d88e2abcba76b4 (patch)
tree753e6ac42a03eb0d46a0a75e9bf118488fb4ca41
parent2fd507d8df3a8ab379689cdda04f854366839838 (diff)
downloadmobly-927dd31baf4f778b4bdbfa38f1d88e2abcba76b4.tar.gz
Progressively increase intervals between adb root attempts (#867)
* Extend the longest possible wait for `adb root` because the low end devices require more time to reconnect after `adb root`. * Fix a typo
-rw-r--r--mobly/controllers/android_device_lib/adb.py10
-rwxr-xr-xtests/mobly/controllers/android_device_lib/adb_test.py4
2 files changed, 8 insertions, 6 deletions
diff --git a/mobly/controllers/android_device_lib/adb.py b/mobly/controllers/android_device_lib/adb.py
index b3994c9..8b55b65 100644
--- a/mobly/controllers/android_device_lib/adb.py
+++ b/mobly/controllers/android_device_lib/adb.py
@@ -29,7 +29,7 @@ ADB_PORT_LOCK = threading.Lock()
# Number of attempts to execute "adb root", and seconds for interval time of
# this commands.
-ADB_ROOT_RETRY_ATTMEPTS = 3
+ADB_ROOT_RETRY_ATTEMPTS = 3
ADB_ROOT_RETRY_ATTEMPT_INTERVAL_SEC = 10
# Qualified class name of the default instrumentation test runner.
@@ -517,7 +517,8 @@ class AdbProxy:
Raises:
AdbError: If the command exit code is not 0.
"""
- for attempt in range(ADB_ROOT_RETRY_ATTMEPTS):
+ retry_interval = ADB_ROOT_RETRY_ATTEMPT_INTERVAL_SEC
+ for attempt in range(ADB_ROOT_RETRY_ATTEMPTS):
try:
return self._exec_adb_cmd('root',
args=None,
@@ -525,12 +526,13 @@ class AdbProxy:
timeout=None,
stderr=None)
except AdbError as e:
- if attempt + 1 < ADB_ROOT_RETRY_ATTMEPTS:
+ if attempt + 1 < ADB_ROOT_RETRY_ATTEMPTS:
logging.debug('Retry the command "%s" since Error "%s" occurred.' %
(utils.cli_cmd_to_string(
e.cmd), e.stderr.decode('utf-8').strip()))
# Buffer between "adb root" commands.
- time.sleep(ADB_ROOT_RETRY_ATTEMPT_INTERVAL_SEC)
+ time.sleep(retry_interval)
+ retry_interval *= 2
else:
raise e
diff --git a/tests/mobly/controllers/android_device_lib/adb_test.py b/tests/mobly/controllers/android_device_lib/adb_test.py
index ecbd813..a013959 100755
--- a/tests/mobly/controllers/android_device_lib/adb_test.py
+++ b/tests/mobly/controllers/android_device_lib/adb_test.py
@@ -769,8 +769,8 @@ class AdbTest(unittest.TestCase):
shell=False,
timeout=None,
stderr=None)
- self.assertEqual(mock_sleep.call_count, 2)
- mock_sleep.assert_called_with(10)
+ self.assertEqual(mock_sleep.call_count, adb.ADB_ROOT_RETRY_ATTEMPTS - 1)
+ mock_sleep.assert_has_calls([mock.call(10), mock.call(20)])
def test_has_shell_command_called_correctly(self):
with mock.patch.object(adb.AdbProxy, '_exec_cmd') as mock_exec_cmd: