diff options
author | Josh Gao <jmgao@google.com> | 2016-09-01 14:54:18 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2016-09-01 15:56:58 -0700 |
commit | 78cc20f00730c5f017550bec2e494523bc052c42 (patch) | |
tree | 0d364310a927a15633f57bf57ed308c4a01e8c0c /adb/test_adb.py | |
parent | 8e7ae1e381b3aefa460d61eb5840ee83c76a4173 (diff) | |
download | system_core-78cc20f00730c5f017550bec2e494523bc052c42.tar.gz system_core-78cc20f00730c5f017550bec2e494523bc052c42.tar.bz2 system_core-78cc20f00730c5f017550bec2e494523bc052c42.zip |
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 'adb/test_adb.py')
-rw-r--r-- | adb/test_adb.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/adb/test_adb.py b/adb/test_adb.py index 0f1b034d8..cb3e0d85e 100644 --- a/adb/test_adb.py +++ b/adb/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) |