|
6 | 6 | from test.support import socket_helper
|
7 | 7 |
|
8 | 8 | import time
|
9 |
| -import errno |
10 | 9 | import socket
|
11 | 10 |
|
12 | 11 |
|
@@ -148,88 +147,6 @@ def setUp(self):
|
148 | 147 | def tearDown(self):
|
149 | 148 | self.sock.close()
|
150 | 149 |
|
151 |
| - @unittest.skipIf(True, 'need to replace these hosts; see bpo-35518') |
152 |
| - def testConnectTimeout(self): |
153 |
| - # Testing connect timeout is tricky: we need to have IP connectivity |
154 |
| - # to a host that silently drops our packets. We can't simulate this |
155 |
| - # from Python because it's a function of the underlying TCP/IP stack. |
156 |
| - # So, the following Snakebite host has been defined: |
157 |
| - blackhole = resolve_address('blackhole.snakebite.net', 56666) |
158 |
| - |
159 |
| - # Blackhole has been configured to silently drop any incoming packets. |
160 |
| - # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back |
161 |
| - # to hosts that attempt to connect to this address: which is exactly |
162 |
| - # what we need to confidently test connect timeout. |
163 |
| - |
164 |
| - # However, we want to prevent false positives. It's not unreasonable |
165 |
| - # to expect certain hosts may not be able to reach the blackhole, due |
166 |
| - # to firewalling or general network configuration. In order to improve |
167 |
| - # our confidence in testing the blackhole, a corresponding 'whitehole' |
168 |
| - # has also been set up using one port higher: |
169 |
| - whitehole = resolve_address('whitehole.snakebite.net', 56667) |
170 |
| - |
171 |
| - # This address has been configured to immediately drop any incoming |
172 |
| - # packets as well, but it does it respectfully with regards to the |
173 |
| - # incoming protocol. RSTs are sent for TCP packets, and ICMP UNREACH |
174 |
| - # is sent for UDP/ICMP packets. This means our attempts to connect to |
175 |
| - # it should be met immediately with ECONNREFUSED. The test case has |
176 |
| - # been structured around this premise: if we get an ECONNREFUSED from |
177 |
| - # the whitehole, we proceed with testing connect timeout against the |
178 |
| - # blackhole. If we don't, we skip the test (with a message about not |
179 |
| - # getting the required RST from the whitehole within the required |
180 |
| - # timeframe). |
181 |
| - |
182 |
| - # For the records, the whitehole/blackhole configuration has been set |
183 |
| - # up using the 'pf' firewall (available on BSDs), using the following: |
184 |
| - # |
185 |
| - # ext_if="bge0" |
186 |
| - # |
187 |
| - # blackhole_ip="35.8.247.6" |
188 |
| - # whitehole_ip="35.8.247.6" |
189 |
| - # blackhole_port="56666" |
190 |
| - # whitehole_port="56667" |
191 |
| - # |
192 |
| - # block return in log quick on $ext_if proto { tcp udp } \ |
193 |
| - # from any to $whitehole_ip port $whitehole_port |
194 |
| - # block drop in log quick on $ext_if proto { tcp udp } \ |
195 |
| - # from any to $blackhole_ip port $blackhole_port |
196 |
| - # |
197 |
| - |
198 |
| - skip = True |
199 |
| - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
200 |
| - timeout = support.LOOPBACK_TIMEOUT |
201 |
| - sock.settimeout(timeout) |
202 |
| - try: |
203 |
| - sock.connect((whitehole)) |
204 |
| - except TimeoutError: |
205 |
| - pass |
206 |
| - except OSError as err: |
207 |
| - if err.errno == errno.ECONNREFUSED: |
208 |
| - skip = False |
209 |
| - finally: |
210 |
| - sock.close() |
211 |
| - del sock |
212 |
| - |
213 |
| - if skip: |
214 |
| - self.skipTest( |
215 |
| - "We didn't receive a connection reset (RST) packet from " |
216 |
| - "{}:{} within {} seconds, so we're unable to test connect " |
217 |
| - "timeout against the corresponding {}:{} (which is " |
218 |
| - "configured to silently drop packets)." |
219 |
| - .format( |
220 |
| - whitehole[0], |
221 |
| - whitehole[1], |
222 |
| - timeout, |
223 |
| - blackhole[0], |
224 |
| - blackhole[1], |
225 |
| - ) |
226 |
| - ) |
227 |
| - |
228 |
| - # All that hard work just to test if connect times out in 0.001s ;-) |
229 |
| - self.addr_remote = blackhole |
230 |
| - with socket_helper.transient_internet(self.addr_remote[0]): |
231 |
| - self._sock_operation(1, 0.001, 'connect', self.addr_remote) |
232 |
| - |
233 | 150 | def testRecvTimeout(self):
|
234 | 151 | # Test recv() timeout
|
235 | 152 | with socket_helper.transient_internet(self.addr_remote[0]):
|
|
0 commit comments