Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection pooling behavior when maxsize > 1 #13

Merged
merged 1 commit into from
Jan 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/with_dummyserver/test_connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ def test_connection_count(self):
self.assertEqual(http_pool.num_connections, 1)
self.assertEqual(http_pool.num_requests, 3)

def test_connection_count_bigpool(self):
http_pool = HTTPConnectionPool(self.host, self.port, maxsize=16)

http_pool.request('GET', '/')
http_pool.request('GET', '/')
http_pool.request('GET', '/')

self.assertEqual(http_pool.num_connections, 1)
self.assertEqual(http_pool.num_requests, 3)

def test_partial_response(self):
http_pool = HTTPConnectionPool(self.host, self.port, maxsize=1)

Expand Down
4 changes: 2 additions & 2 deletions urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


from httplib import HTTPConnection, HTTPSConnection, HTTPException
from Queue import Queue, Empty, Full
from Queue import LifoQueue, Empty, Full
from select import select
from socket import error as SocketError, timeout as SocketTimeout

Expand Down Expand Up @@ -129,7 +129,7 @@ def __init__(self, host, port=None, strict=False, timeout=None, maxsize=1,
self.port = port
self.strict = strict
self.timeout = timeout
self.pool = Queue(maxsize)
self.pool = LifoQueue(maxsize)
self.block = block
self.headers = headers or {}

Expand Down