def test_basic_acquire(self): pool = ConnectionPool(max_host_count=2) conn1 = yield From(pool.acquire('localhost', self.get_http_port())) conn2 = yield From(pool.acquire('localhost', self.get_http_port())) yield From(pool.release(conn1)) yield From(pool.release(conn2)) conn3 = yield From(pool.acquire('localhost', self.get_http_port())) conn4 = yield From(pool.acquire('localhost', self.get_http_port())) yield From(pool.release(conn3)) yield From(pool.release(conn4))
def test_clean(self): pool = ConnectionPool(max_host_count=2) conn1 = yield From(pool.acquire('localhost', self.get_http_port())) conn2 = yield From(pool.acquire('localhost', self.get_http_port())) yield From(pool.release(conn1)) yield From(pool.release(conn2)) yield From(pool.clean()) self.assertEqual(0, len(pool.host_pools))
def test_connection_pool_release_clean_race_condition(self): pool = ConnectionPool(max_host_count=1) connection = yield From(pool.acquire('127.0.0.1', 1234)) connection_2_task = trollius.async(pool.acquire('127.0.0.1', 1234)) yield From(trollius.sleep(0.01)) pool.no_wait_release(connection) yield From(pool.clean(force=True)) connection_2 = yield From(connection_2_task) # This line should not KeyError crash: yield From(pool.release(connection_2))
def test_connection_pool_release_clean_race_condition(self): pool = ConnectionPool(max_host_count=1) connection = yield From(pool.acquire('127.0.0.1', 1234)) connection_2_task = trollius. async (pool.acquire('127.0.0.1', 1234)) yield From(trollius.sleep(0.01)) pool.no_wait_release(connection) yield From(pool.clean(force=True)) connection_2 = yield From(connection_2_task) # This line should not KeyError crash: yield From(pool.release(connection_2))
def test_happy_eyeballs_prefer_ipv6(self): connection_factory = functools.partial(Connection, connect_timeout=10) resolver = Resolver(family=Resolver.PREFER_IPv6) pool = ConnectionPool(resolver=resolver, connection_factory=connection_factory) conn1 = yield From(pool.acquire('google.com', 80)) conn2 = yield From(pool.acquire('google.com', 80)) yield From(conn1.connect()) yield From(conn2.connect()) conn1.close() conn2.close() yield From(pool.release(conn1)) yield From(pool.release(conn2)) conn3 = yield From(pool.acquire('google.com', 80)) yield From(conn3.connect()) conn3.close() yield From(pool.release(conn3))