From e2576ba3cfab22d91267a0322ffc409757494adf Mon Sep 17 00:00:00 2001 From: Douglas Farinelli Date: Fri, 16 Jul 2021 11:09:26 -0300 Subject: [PATCH] Fix connection basic query arguments --- aredis/pool.py | 6 +- tests/client/test_connection_pool.py | 90 +++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/aredis/pool.py b/aredis/pool.py index 1fbb2cc7..905c54e9 100644 --- a/aredis/pool.py +++ b/aredis/pool.py @@ -33,7 +33,11 @@ def to_bool(value): URL_QUERY_ARGUMENT_PARSERS = { 'stream_timeout': float, 'connect_timeout': float, - 'retry_on_timeout': to_bool + 'retry_on_timeout': to_bool, + 'max_connections': int, + 'max_idle_time': int, + 'idle_check_interval': int, + 'reader_read_size': int } diff --git a/tests/client/test_connection_pool.py b/tests/client/test_connection_pool.py index f07d903c..247d5e13 100644 --- a/tests/client/test_connection_pool.py +++ b/tests/client/test_connection_pool.py @@ -86,7 +86,7 @@ async def test_connection_idle_check(self, event_loop): assert last_active_at == conn.last_active_at assert conn._writer is None and conn._reader is None - + class TestConnectionPoolURLParsing: def test_defaults(self): pool = aredis.ConnectionPool.from_url('redis://localhost') @@ -225,6 +225,50 @@ def test_invalid_extra_typed_querystring_options(self): 'Invalid value for `stream_timeout` in connection URL.', ] + def test_max_connections_querystring_option(self): + pool = aredis.ConnectionPool.from_url('redis://localhost?max_connections=32') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'max_connections': 32 + } + + def test_max_idle_times_querystring_option(self): + pool = aredis.ConnectionPool.from_url('redis://localhost?max_idle_time=5') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'max_idle_time': 5 + } + + def test_idle_check_interval_querystring_option(self): + pool = aredis.ConnectionPool.from_url('redis://localhost?idle_check_interval=1') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'idle_check_interval': 1 + } + + def test_reader_read_size_querystring_option(self): + pool = aredis.ConnectionPool.from_url('redis://localhost?reader_read_size=65535') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'reader_read_size': 65535 + } + def test_extra_querystring_options(self): pool = aredis.ConnectionPool.from_url('redis://localhost?a=1&b=2') assert pool.connection_class == aredis.Connection @@ -307,6 +351,50 @@ def test_db_in_querystring(self): 'password': None, } + def test_max_connections_querystring_option(self): + pool = aredis.ConnectionPool.from_url('unix:///localhost?max_connections=32') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'max_connections': 32 + } + + def test_max_idle_times_querystring_option(self): + pool = aredis.ConnectionPool.from_url('unix:///localhost?max_idle_time=5') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'max_idle_time': 5 + } + + def test_idle_check_interval_querystring_option(self): + pool = aredis.ConnectionPool.from_url('unix:///localhost?idle_check_interval=1') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'idle_check_interval': 1 + } + + def test_reader_read_size_querystring_option(self): + pool = aredis.ConnectionPool.from_url('unix:///localhost?reader_read_size=65535') + assert pool.connection_class == aredis.Connection + assert pool.connection_kwargs == { + 'host': 'localhost', + 'port': 6379, + 'db': 0, + 'password': None, + 'reader_read_size': 65535 + } + def test_extra_querystring_options(self): pool = aredis.ConnectionPool.from_url('unix:///socket?a=1&b=2') assert pool.connection_class == aredis.UnixDomainSocketConnection