aboutsummaryrefslogtreecommitdiff
path: root/test_adb.py
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2016-09-01 14:54:18 -0700
committerJosh Gao <jmgao@google.com>2016-09-01 15:56:58 -0700
commit50bde8d487c6a1fab7e5c019df0956b16690c947 (patch)
tree82460160f5eeea6d8d102fb4e1b11a9ecb2daed6 /test_adb.py
parent827a4a575d5a880f68d2647f9d4a581aca0341fc (diff)
downloadadb-50bde8d487c6a1fab7e5c019df0956b16690c947.tar.gz
libcutils: try all addresses in socket_network_client_timeout.
If a connection fails to an address that resolves to multiple sockaddrs, attempt connecting to subsequent addresses if the initial connection fails to a reason other than timeout. This is primarily useful for localhost, which can resolve to both an IPv4 and and IPv6 address. Also, add an adb test to verify that this behavior. Bug: http://b/30313466 Change-Id: Ib2df706a66cf6ef8c1097fdfd7aedb69b8df2d6e Test: python test_adb.py (+ the test fails before this patch)
Diffstat (limited to 'test_adb.py')
-rw-r--r--test_adb.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/test_adb.py b/test_adb.py
index 0f1b034d..cb3e0d85 100644
--- a/test_adb.py
+++ b/test_adb.py
@@ -207,6 +207,28 @@ class NonApiTest(unittest.TestCase):
# reading the response from the adb emu kill command (on Windows).
self.assertEqual(0, p.returncode)
+ def test_connect_ipv4_ipv6(self):
+ """Ensure that `adb connect localhost:1234` will try both IPv4 and IPv6.
+
+ Bug: http://b/30313466
+ """
+ ipv4 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ ipv4.bind(('127.0.0.1', 0))
+ ipv4.listen(1)
+
+ ipv6 = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+ ipv6.bind(('::1', ipv4.getsockname()[1] + 1))
+ ipv6.listen(1)
+
+ for s in (ipv4, ipv6):
+ port = s.getsockname()[1]
+ output = subprocess.check_output(
+ ['adb', 'connect', 'localhost:{}'.format(port)])
+
+ self.assertEqual(
+ output.strip(), 'connected to localhost:{}'.format(port))
+ s.close()
+
def main():
random.seed(0)