Skip to content

Commit 9d538e9

Browse files
committed
work around urllib3 socket leak
urllib3/urllib3#2570
1 parent 516999d commit 9d538e9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/test_server.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import os
21
import contextlib
2+
import os
3+
import re
4+
import socket
35

46
import pytest
57
import requests
@@ -40,10 +42,22 @@ def test_server_should_be_http_1_1(httpbin):
4042
assert resp.startswith(b"HTTP/1.1")
4143

4244

43-
def test_dont_crash_on_certificate_problems(httpbin_secure):
44-
with pytest.raises(Exception):
45+
def test_dont_crash_on_certificate_problems(httpbin_secure, capsys):
46+
with socket.socket() as sock:
47+
sock.connect((httpbin_secure.host, httpbin_secure.port))
4548
# this request used to hang
46-
requests.get(httpbin_secure + "/get", verify=True, cert=__file__)
49+
assert sock.recv(1) == b""
50+
51+
assert (
52+
re.match(
53+
r"pytest-httpbin server hit an exception serving request: .* The "
54+
"handshake operation timed out\nattempting to ignore so the rest "
55+
"of the tests can run\n",
56+
capsys.readouterr().out,
57+
)
58+
is not None
59+
)
60+
4761
# and this request would never happen
4862
requests.get(
4963
httpbin_secure + "/get",

0 commit comments

Comments
 (0)