Skip to content

Commit

Permalink
Skip test on Windows?
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Aug 28, 2020
1 parent 6dbdc06 commit c9497d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/urllib3/connectionpool.py
Expand Up @@ -399,17 +399,14 @@ def _make_request(
except BrokenPipeError:
# Python 3
pass
except Exception as e:
print("ERROR=", e, e.args, "errno=", getattr(e, "errno", None))
# Python 2, Windows, macOS
except IOError as e:
# Python 2 and macOS/Linux
# EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE is needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
# Windows is ConnectionAborted which can mean that a connection hung up.
if getattr(e, "errno", None) not in {
if e.errno not in {
errno.EPIPE,
errno.ESHUTDOWN,
errno.EPROTOTYPE,
errno.ECONNABORTED,
}:
raise

Expand Down Expand Up @@ -1060,3 +1057,4 @@ def _normalize_host(host, scheme):
if host.startswith("[") and host.endswith("]"):
host = host[1:-1]
return host

14 changes: 14 additions & 0 deletions test/__init__.py
Expand Up @@ -152,6 +152,19 @@ def wrapper(*args, **kwargs):
return wrapper


def notWindows(test):
"""Skips this test when running on Windows"""

@six.wraps(test)
def wrapper(*args, **kwargs):
msg = "{name} does not run on Windows".format(name=test.__name__)
if platform.system() == "Windows":
pytest.skip(msg)
return test(*args, **kwargs)

return wrapper


def notOpenSSL098(test):
"""Skips this test for Python 3.5 macOS python.org distribution"""

Expand Down Expand Up @@ -295,3 +308,4 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
self.uninstall()
return False

15 changes: 13 additions & 2 deletions test/with_dummyserver/test_socketlevel.py
Expand Up @@ -57,6 +57,7 @@ class MimeToolMessage(object):
LONG_TIMEOUT,
notPyPy2,
notSecureTransport,
notWindows,
resolvesLocalhostFQDN,
)

Expand Down Expand Up @@ -1783,7 +1784,10 @@ def socket_handler(listener):


class TestBrokenPipe(SocketDummyServerTestCase):
def test_broken_pipe_ignore(self, monkeypatch):
@notWindows
def test_ignore_broken_pipe_errors(self, monkeypatch):
# On Windows an aborted connection raises an error on
# attempts to read data out of a socket that's been closed.
sock_shut = Event()
orig_connect = HTTPConnection.connect
# a buffer that will cause two sendall calls
Expand All @@ -1800,8 +1804,9 @@ def socket_handler(listener):
sock.send(
b"HTTP/1.1 404 Not Found\r\n"
b"Connection: close\r\n"
b"Content-Length: 0\r\n"
b"Content-Length: 10\r\n"
b"\r\n"
b"xxxxxxxxxx"
)
sock.shutdown(socket.SHUT_RDWR)
sock_shut.set()
Expand All @@ -1812,5 +1817,11 @@ def socket_handler(listener):
with HTTPConnectionPool(self.host, self.port) as pool:
r = pool.request("POST", "/", body=buf)
assert r.status == 404
assert r.headers["content-length"] == "10"
assert r.data == b"xxxxxxxxxx"

r = pool.request("POST", "/admin", chunked=True, body=buf)
assert r.status == 404
assert r.headers["content-length"] == "10"
assert r.data == b"xxxxxxxxxx"

0 comments on commit c9497d0

Please sign in to comment.