comparison tests/test_push_command.py @ 1501:6e3f48d8002f

tests: fix ipv6 support in test_push_command.py This test runs the `svnserve` binary, which appears to resolve the hostname passed as an argument using gethostbyname(3), which can only return an IPv4 address. When run on a system that is configured to only have an IPv6 address, Mercurial will correctly resolve the hostname to an IPv6 address, but the SVN server will be listening on an incorrect IPv4 address, causing the test to fail. The workaround is to resolve the hostname using getaddrinfo(3) in the test harness and pass the resulting address to svnserve.
author Arun Kulshreshtha <kulshrax@fb.com>
date Mon, 10 Apr 2017 16:58:28 -0700
parents 945700dac237
children debba0fa822e
comparison
equal deleted inserted replaced
1500:f75c1d112793 1501:6e3f48d8002f
137 repo_path = self.load_svndump('simple_branch.svndump') 137 repo_path = self.load_svndump('simple_branch.svndump')
138 open(os.path.join(repo_path, 'conf', 'svnserve.conf'), 138 open(os.path.join(repo_path, 'conf', 'svnserve.conf'),
139 'w').write('[general]\nanon-access=write\n[sasl]\n') 139 'w').write('[general]\nanon-access=write\n[sasl]\n')
140 self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) 140 self.port = random.randint(socket.IPPORT_USERRESERVED, 65535)
141 self.host = socket.gethostname() 141 self.host = socket.gethostname()
142
143 # The `svnserve` binary appears to use the obsolete `gethostbyname(3)`
144 # function, which always returns an IPv4 address, even on hosts that
145 # support and expect IPv6. As a workaround, resolve the hostname
146 # within the test harness with `getaddrinfo(3)` to ensure that the
147 # client and server both use the same IPv4 or IPv6 address.
148 addrinfo = socket.getaddrinfo(self.host, self.port)
149 self.host = addrinfo[0][4][0]
150
151 # If we're connecting via IPv6 the need to put brackets around the
152 # hostname in the URL.
153 ipv6 = addrinfo[0][0] == socket.AF_INET6
154 urlfmt = 'svn://[%s]:%d/%s' if ipv6 else 'svn://%s:%d/%s'
155
142 args = ['svnserve', '--daemon', '--foreground', 156 args = ['svnserve', '--daemon', '--foreground',
143 '--listen-port=%d' % self.port, 157 '--listen-port=%d' % self.port,
144 '--listen-host=%s' % self.host, 158 '--listen-host=%s' % self.host,
145 '--root=%s' % repo_path] 159 '--root=%s' % repo_path]
146 160
150 try: 164 try:
151 time.sleep(2) 165 time.sleep(2)
152 import shutil 166 import shutil
153 shutil.rmtree(self.wc_path) 167 shutil.rmtree(self.wc_path)
154 commands.clone(self.ui(), 168 commands.clone(self.ui(),
155 'svn://%s:%d/%s' % (self.host, self.port, subdir), 169 urlfmt % (self.host, self.port, subdir),
156 self.wc_path, noupdate=True) 170 self.wc_path, noupdate=True)
157 171
158 repo = self.repo 172 repo = self.repo
159 old_tip = repo['tip'].node() 173 old_tip = repo['tip'].node()
160 expected_parent = repo['default'].node() 174 expected_parent = repo['default'].node()