python-urllib3/ready-event.patch

107 lines
4.5 KiB
Diff
Raw Normal View History

Index: urllib3-1.12/dummyserver/testcase.py
===================================================================
--- urllib3-1.12.orig/dummyserver/testcase.py
+++ urllib3-1.12/dummyserver/testcase.py
@@ -45,7 +45,7 @@ class SocketDummyServerTestCase(unittest
def socket_handler(listener):
for _ in range(num):
ready_event.set()
- ready_event.clear()
+ #ready_event.clear()
sock = listener.accept()[0]
consume_socket(sock)
@@ -59,6 +59,11 @@ class SocketDummyServerTestCase(unittest
return ready_event
@classmethod
+ def wait_for_socket(cls, ready_event):
+ ready_event.wait()
+ ready_event.clear()
+
+ @classmethod
def start_basic_handler(cls, **kw):
return cls.start_response_handler(
b'HTTP/1.1 200 OK\r\n'
Index: urllib3-1.12/test/with_dummyserver/test_connectionpool.py
===================================================================
--- urllib3-1.12.orig/test/with_dummyserver/test_connectionpool.py
+++ urllib3-1.12/test/with_dummyserver/test_connectionpool.py
@@ -57,11 +57,12 @@ class TestConnectionPoolTimeouts(SocketD
# Pool-global timeout
pool = HTTPConnectionPool(self.host, self.port, timeout=SHORT_TIMEOUT, retries=False)
+ self.wait_for_socket(ready_event)
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/')
block_event.set() # Release block
# Shouldn't raise this time
- ready_event.wait()
+ self.wait_for_socket(ready_event)
block_event.set() # Pre-release block
pool.request('GET', '/')
@@ -92,12 +93,13 @@ class TestConnectionPoolTimeouts(SocketD
timeout = Timeout(read=SHORT_TIMEOUT)
pool = HTTPConnectionPool(self.host, self.port, timeout=timeout, retries=False)
+ self.wait_for_socket(ready_event)
conn = pool._get_conn()
self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/')
pool._put_conn(conn)
block_event.set() # Release request
- ready_event.wait()
+ self.wait_for_socket(ready_event)
block_event.clear()
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/')
block_event.set() # Release request
@@ -106,7 +108,7 @@ class TestConnectionPoolTimeouts(SocketD
pool = HTTPConnectionPool(self.host, self.port, timeout=LONG_TIMEOUT, retries=False)
conn = pool._get_conn()
- ready_event.wait()
+ self.wait_for_socket(ready_event)
now = time.time()
self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/', timeout=timeout)
delta = time.time() - now
@@ -115,7 +117,7 @@ class TestConnectionPoolTimeouts(SocketD
self.assertTrue(delta < LONG_TIMEOUT, "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT")
pool._put_conn(conn)
- ready_event.wait()
+ self.wait_for_socket(ready_event)
now = time.time()
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/', timeout=timeout)
delta = time.time() - now
@@ -125,11 +127,11 @@ class TestConnectionPoolTimeouts(SocketD
# Timeout int/float passed directly to request and _make_request should
# raise a request timeout
- ready_event.wait()
+ self.wait_for_socket(ready_event)
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/', timeout=SHORT_TIMEOUT)
block_event.set() # Release request
- ready_event.wait()
+ self.wait_for_socket(ready_event)
conn = pool._new_conn()
# FIXME: This assert flakes sometimes. Not sure why.
self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/', timeout=SHORT_TIMEOUT)
@@ -183,13 +185,14 @@ class TestConnectionPoolTimeouts(SocketD
block_event = Event()
ready_event = self.start_basic_handler(block_send=block_event, num=2)
+ self.wait_for_socket(ready_event)
# This will get the socket to raise an EAGAIN on the read
timeout = Timeout(connect=3, read=SHORT_TIMEOUT)
pool = HTTPConnectionPool(self.host, self.port, timeout=timeout, retries=False)
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/')
block_event.set()
- ready_event.wait()
+ self.wait_for_socket(ready_event)
block_event.clear()
# The connect should succeed and this should hit the read timeout