示例#1
0
    def test_host_max_limit(self):
        pool = ConnectionPool(max_host_count=2)

        yield from pool.acquire('localhost', self.get_http_port())
        yield from pool.acquire('localhost', self.get_http_port())

        with self.assertRaises(asyncio.TimeoutError):
            yield from asyncio.wait_for(
                pool.acquire('localhost', self.get_http_port()), 0.1)
示例#2
0
    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 = asyncio. async (pool.acquire('127.0.0.1', 1234))
        yield from asyncio.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)
示例#3
0
    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)
示例#4
0
    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))
示例#5
0
    def test_happy_eyeballs(self):
        connection_factory = functools.partial(Connection, connect_timeout=10)
        resolver = Resolver()
        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)