def test_pool_edgecases(self): pool = HTTPConnectionPool(host='localhost', maxsize=1, block=False) conn1 = yield From(pool._get_conn(timeout=0.1)) conn2 = yield From(pool._get_conn(timeout=0.1)) # New because block=False pool._put_conn(conn1) pool._put_conn(conn2) # Should be discarded self.assertEqual(conn1, (yield From(pool._get_conn()))) self.assertNotEqual(conn2, (yield From(pool._get_conn(timeout=0.1)))) self.assertEqual(pool.num_connections, 3)
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)