aboutsummaryrefslogtreecommitdiff
path: root/test_adb.py
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2018-04-03 12:55:18 -0700
committerJosh Gao <jmgao@google.com>2018-04-03 13:58:21 -0700
commit13781e8a805f3f2fba7f2074124eed8b428db457 (patch)
tree3d3790461d1b5952d1f90ad1ce61c627601c46f4 /test_adb.py
parent205a8f4e13e7adbf00248ef00887209522bb1988 (diff)
downloadadb-13781e8a805f3f2fba7f2074124eed8b428db457.tar.gz
adb: don't abort when connecting to the same address twice.
When connecting to an address, we construct a transport first, and then check whether we've already connected to that address. The consequent destruction of the BlockingConnectionAdapter attempts to join threads that haven't been started, which aborts. Make it safe to destruct a BlockingConnectionAdapter without calling Start on it first, to solve this. Bug: http://b/69137547 Test: nc -l 12345 & (adb connect localhost:12345; adb connect localhost:12345) Test: python test_adb.py Change-Id: I6cb968a62dbac6332907e06575893d764905ee62
Diffstat (limited to 'test_adb.py')
-rw-r--r--test_adb.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/test_adb.py b/test_adb.py
index e7711062..3bb433dd 100644
--- a/test_adb.py
+++ b/test_adb.py
@@ -162,15 +162,14 @@ class NonApiTest(unittest.TestCase):
Bug: https://code.google.com/p/android/issues/detail?id=21021
"""
- port = 12345
-
with contextlib.closing(
socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as listener:
# Use SO_REUSEADDR so subsequent runs of the test can grab the port
# even if it is in TIME_WAIT.
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- listener.bind(('127.0.0.1', port))
+ listener.bind(('127.0.0.1', 0))
listener.listen(4)
+ port = listener.getsockname()[1]
# Now that listening has started, start adb emu kill, telling it to
# connect to our mock emulator.
@@ -233,6 +232,24 @@ class NonApiTest(unittest.TestCase):
output.strip(), 'connected to localhost:{}'.format(port))
s.close()
+ def test_already_connected(self):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.bind(('127.0.0.1', 0))
+ s.listen(2)
+
+ port = s.getsockname()[1]
+ output = subprocess.check_output(
+ ['adb', 'connect', 'localhost:{}'.format(port)])
+
+ self.assertEqual(
+ output.strip(), 'connected to localhost:{}'.format(port))
+
+ # b/31250450: this always returns 0 but probably shouldn't.
+ output = subprocess.check_output(
+ ['adb', 'connect', 'localhost:{}'.format(port)])
+
+ self.assertEqual(
+ output.strip(), 'already connected to localhost:{}'.format(port))
def main():
random.seed(0)