def test_max_connections(self):
        pool = HTTPConnectionPool(host='localhost', maxsize=1, block=True)

        try:
            yield From(pool._get_conn(timeout=0.1))

            try:
                yield From(pool._get_conn(timeout=0.1))
                self.fail("Managed to get a connection without EmptyPoolError")
            except EmptyPoolError:
                pass

            try:
                yield From(pool.request('GET', '/', pool_timeout=0.1))
                self.fail("Managed to get a connection without EmptyPoolError")
            except EmptyPoolError:
                pass

        except Exception as e:
            self.assertTrue(False)

        self.assertEqual(pool.num_connections, 1)
    def test_pool_size(self):
        POOL_SIZE = 1
        pool = HTTPConnectionPool(host='localhost', maxsize=POOL_SIZE, block=True)

        def _raise(ex):
            raise ex()

        def _test(exception, expect):
            pool._make_request = lambda *args, **kwargs: _raise(exception)
            try:
                yield From(pool.request('GET', '/'))
            except expect:
                pass
            else:
                self.assertTrue(False, 'Expected exception %s not raised' % expect)

            self.assertEqual(pool.pool.qsize(), POOL_SIZE)

        # Make sure that all of the exceptions return the connection to the pool
        _test(Empty, EmptyPoolError)
        _test(BaseSSLError, SSLError)
        _test(CertificateError, SSLError)

        # The pool should never be empty, and with these two exceptions being raised,
        # a retry will be triggered, but that retry will fail, eventually raising
        # MaxRetryError, not EmptyPoolError
        # See: https://github.com/shazow/urllib3/issues/76
        pool._make_request = lambda *args, **kwargs: _raise(HTTPException)
        try:
            yield From(pool.request('GET', '/', retries=1, pool_timeout=0.01))
        except MaxRetryError:
            pass
        else:
            self.assertTrue(False, 'MaxRetryError not raised')

        self.assertEqual(pool.pool.qsize(), POOL_SIZE)