def test_get_connection(loop, make_pool): c1 = Connection(Endpoint('http', 'h1', 1), loop=loop) c2 = Connection(Endpoint('http', 'h2', 2), loop=loop) pool = make_pool(connections=[c1, c2]) yield from pool.mark_dead(c1) yield from pool.mark_dead(c2) conn = yield from pool.get_connection() assert 1 == pool._dead.qsize() assert c1 is conn
def go(): c1 = Connection(Endpoint('http', 'h1', 1), loop=self.loop) c2 = Connection(Endpoint('http', 'h2', 2), loop=self.loop) pool = self.make_pool(connections=[c1, c2]) yield from pool.mark_dead(c1) yield from pool.mark_dead(c2) conn = yield from pool.get_connection() self.assertEqual(1, pool._dead.qsize()) self.assertIs(c1, conn)
def go(): c1 = Connection(Endpoint('http', 'h1', 1), loop=self.loop) c2 = Connection(Endpoint('http', 'h2', 2), loop=self.loop) pool = self.make_pool(connections=[c1, c2]) yield from pool.mark_dead(c1) yield from pool.mark_dead(c2) yield from pool.resurrect() self.assertEqual(2, pool._dead.qsize()) yield from pool.resurrect(True) self.assertEqual(1, pool._dead.qsize()) self.assertEqual([c1], pool.connections)
def test_resurrect(loop, make_pool): c1 = Connection(Endpoint('http', 'h1', 1), loop=loop) c2 = Connection(Endpoint('http', 'h2', 2), loop=loop) pool = make_pool(connections=[c1, c2]) yield from pool.mark_dead(c1) yield from pool.mark_dead(c2) yield from pool.resurrect() assert 2 == pool._dead.qsize() yield from pool.resurrect(True) assert 1 == pool._dead.qsize() assert [c1] == pool.connections
def go(): pool = self.make_pool(connections=[]) conn = Connection(Endpoint('http', 'localhost', 9200), loop=self.loop) yield from pool.mark_live(conn) self.assertNotIn(conn, pool._dead_count)
def go(*, no_loop=False, **kwargs): nonlocal conn conn = Connection(Endpoint('http', es_params['host'], es_params['port']), loop=loop) conns.append(conn) return conn
def make_pool(self, connections=default): if connections is default: connections = [ Connection(Endpoint('http', 'localhost', 9200), loop=self.loop) ] pool = ConnectionPool(connections, loop=self.loop) self.addCleanup(pool.close) return pool
def test_bad_status_409(loop): conn = Connection(Endpoint('http', 'host', 9999), loop=loop) resp = mock.Mock() resp.status = 409 r2 = asyncio.Future(loop=loop) r2.set_result('{"a": 1}') resp.text.return_value = r2 fut = asyncio.Future(loop=loop) fut.set_result(resp) conn._session.request = mock.Mock(return_value=fut) with pytest.raises(ConflictError) as ctx: yield from conn.perform_request('GET', '/data', None, None) assert 409 == ctx.value.status_code assert '{"a": 1}' == ctx.value.error assert {"a": 1} == ctx.value.info
def go(): conn = Connection(Endpoint('http', 'host', 9999), loop=self.loop) resp = mock.Mock() resp.status = 404 r2 = asyncio.Future(loop=self.loop) r2.set_result('{"a": 1}') resp.text.return_value = r2 fut = asyncio.Future(loop=self.loop) fut.set_result(resp) conn._session.request = mock.Mock(return_value=fut) with self.assertRaises(NotFoundError) as ctx: yield from conn.perform_request('GET', '/data', None, None) self.assertEqual(404, ctx.exception.status_code) self.assertEqual('{"a": 1}', ctx.exception.error) self.assertEqual({"a": 1}, ctx.exception.info)
def test_ctor(loop): c = Connection(Endpoint('http', 'host', 9999), loop=loop) assert Endpoint('http', 'host', 9999) == c.endpoint
def test_use_connector_param(loop): connector = aiohttp.TCPConnector(loop=loop) c = Connection(Endpoint('http', 'host', 9999), loop=loop, connector=connector) assert c._session.connector is connector
def test_ctor(self): c = Connection(Endpoint('http', 'host', 9999), loop=self.loop) self.assertEqual(Endpoint('http', 'host', 9999), c.endpoint)