diff options
author | Josh Gao <jmgao@google.com> | 2020-03-02 20:46:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-02 20:46:15 +0000 |
commit | 9978c367548fa29473bef75dc5836000d10ad71c (patch) | |
tree | ce5381761474a3bbc1800c2abf03b665a233e65d /adb/test_adb.py | |
parent | acb49fd07d328d6cb87fd8d9bdf49fbbaffe58a4 (diff) | |
parent | bbe3385097750842a8d87b9d3d0248c937dcdb97 (diff) |
Merge changes Ib97acc6d,I8f14004a,Id5bbfd6d,I4dfc3f52 into rvc-dev
* changes:
adbd: add runtime-configurable logging.
adb: don't hardcode ports in test_adb.
adbd: add usb thread spawn logging.
base: add CachedProperty.
Diffstat (limited to 'adb/test_adb.py')
-rwxr-xr-x | adb/test_adb.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/adb/test_adb.py b/adb/test_adb.py index 3d6de2665d..c872fb0f72 100755 --- a/adb/test_adb.py +++ b/adb/test_adb.py @@ -33,6 +33,11 @@ import time import unittest import warnings +def find_open_port(): + # Find an open port. + with socket.socket() as s: + s.bind(("localhost", 0)) + return s.getsockname()[1] @contextlib.contextmanager def fake_adbd(protocol=socket.AF_INET, port=0): @@ -126,10 +131,7 @@ def adb_server(): This creates an ADB server and returns the port it's listening on. """ - port = 5038 - # Kill any existing server on this non-default port. - subprocess.check_output(["adb", "-P", str(port), "kill-server"], - stderr=subprocess.STDOUT) + port = find_open_port() read_pipe, write_pipe = os.pipe() if sys.platform == "win32": @@ -224,10 +226,7 @@ class ServerTest(unittest.TestCase): # adb server, this also tests whether multiple instances of the adb # server conflict on adb.log. - port = 5038 - # Kill any existing server on this non-default port. - subprocess.check_output(["adb", "-P", str(port), "kill-server"], - stderr=subprocess.STDOUT) + port = find_open_port() try: # We get warnings for unclosed files for the subprocess's pipes, @@ -289,12 +288,8 @@ class ServerTest(unittest.TestCase): """ Tests that the server can start up on ::1 and that it's accessible """ - server_port = 5037 - # Kill any existing server on this non-default port. - subprocess.check_output( - ["adb", "-P", str(server_port), "kill-server"], - stderr=subprocess.STDOUT, - ) + + server_port = find_open_port() try: subprocess.check_output( ["adb", "-L", "tcp:[::1]:{}".format(server_port), "server"], |