Example #1
0
def test_concurrency_constructor():
    Concurrency(3)
    Concurrency(max_concurrent=0)
    Concurrency(max_concurrent=32)
    with pytest.raises(RuntimeError):
        Concurrency(max_concurrent=-1)
    with pytest.raises(RuntimeError):
        Concurrency(max_concurrent=2.5)
Example #2
0
 def __init__(self, *, framer=None, loop=None):
     self.framer = framer or self.default_framer()
     self.loop = loop or asyncio.get_event_loop()
     self.logger = logging.getLogger(self.__class__.__name__)
     self.transport = None
     self.closed_event = self.event()
     # Set when a connection is made
     self._address = None
     self._proxy_address = None
     # For logger.debug messsages
     self.verbosity = 0
     # Cleared when the send socket is full
     self._can_send = self.event()
     self._can_send.set()
     self._task_group = TaskGroup()
     # Force-close a connection if a send doesn't succeed in this time
     self.max_send_delay = 60
     # Statistics.  The RPC object also keeps its own statistics.
     self.start_time = time.time()
     self.errors = 0
     self.send_count = 0
     self.send_size = 0
     self.last_send = self.start_time
     self.recv_count = 0
     self.recv_size = 0
     self.last_recv = self.start_time
     # Bandwidth usage per hour before throttling starts
     self.bw_limit = 2000000
     self.bw_time = self.start_time
     self.bw_charge = 0
     # Concurrency control
     self.max_concurrent = 6
     self._concurrency = Concurrency(self.max_concurrent)
Example #3
0
async def test_max_concurrent():
    c = Concurrency(max_concurrent=3)
    assert c.max_concurrent == 3
    assert await concurrency_max(c) == 3
    await c.set_max_concurrent(3)
    assert c.max_concurrent == 3
    assert await concurrency_max(c) == 3
    await c.set_max_concurrent(1)
    assert c.max_concurrent == 1
    assert await concurrency_max(c) == 1
    await c.set_max_concurrent(0)
    assert c.semaphore._value == 0
    assert c.max_concurrent == 0
    assert await concurrency_max(c) == 0
    await c.set_max_concurrent(5)
    assert c.max_concurrent == 5
    assert await concurrency_max(c) == 5
    with pytest.raises(RuntimeError):
        await c.set_max_concurrent(-1)
    with pytest.raises(RuntimeError):
        await c.set_max_concurrent(2.6)
 def __init__(self, connection=None, framer=None, loop=None):
     self.connection = connection or self.default_connection()
     self.framer = framer or self.default_framer()
     self.loop = loop or asyncio.get_event_loop()
     self.logger = logging.getLogger(self.__class__.__name__)
     self.transport = None
     # Concurrency
     self.max_concurrent = 6
     # Set when a connection is made
     self._address = None
     self._proxy_address = None
     # For logger.debug messsages
     self.verbosity = 0
     # Pausing sends when socket is full
     self.paused = False
     self.paused_messages = []
     # Close once the send queue is exhausted.  An unfortunate hack
     # necessitated by asyncio's non-blocking socket writes
     self.close_after_send = False
     # Statistics.  The RPC object also keeps its own statistics.
     self.start_time = time.time()
     self.errors = 0
     self.send_count = 0
     self.send_size = 0
     self.last_send = self.start_time
     self.recv_count = 0
     self.recv_size = 0
     self.last_recv = self.start_time
     # Bandwidth usage per hour before throttling starts
     self.bw_limit = 2000000
     self.bw_time = self.start_time
     self.bw_charge = 0
     # Concurrency control
     self.concurrency = Concurrency(self.max_concurrent)
     self.work_queue = Queue()
     self.pm_task = None