diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2019-07-22 17:14:28 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2019-07-23 14:48:30 -0700 |
commit | 0984b102264b2600a6534ad8fef6f4cab44b4ecc (patch) | |
tree | c1aad6c05ff0e021626ae94f76eb502a532af782 /tests/conftest.py | |
parent | 6e23760fefbdf27ec941a2c3ae1ec2657875ac31 (diff) | |
download | redis-py-0984b102264b2600a6534ad8fef6f4cab44b4ecc.tar.gz |
Ability to create a client that uses a single connection
This has multiple uses:
* Single connection clients will not be considered threadsafe. This means
certain settings could temporarily be adjusted. For example, a context
manager could temporarily modify the encoding behavior for a set
of commands.
* We can introduce more thorough health checks that only happen when a
connection is handed out from the connection pool.
* Workloads that issue many commands to Redis should be slightly faster.
Prior to this change, the client must retrieve a connection from the
pool for each command.
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 0ab6428..87e6301 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -53,9 +53,11 @@ def skip_unless_arch_bits(arch_bits): reason="server is not {}-bit".format(arch_bits)) -def _get_client(cls, request, **kwargs): +def _get_client(cls, request, single_connection_client=True, **kwargs): redis_url = request.config.getoption("--redis-url") client = cls.from_url(redis_url, **kwargs) + if single_connection_client: + client = client.client() if request: def teardown(): try: @@ -64,31 +66,27 @@ def _get_client(cls, request, **kwargs): # handle cases where a test disconnected a client # just manually retry the flushdb client.flushdb() + client.close() client.connection_pool.disconnect() request.addfinalizer(teardown) return client @pytest.fixture() -def r(request, **kwargs): - return _get_client(redis.Redis, request, **kwargs) +def r(request): + return _get_client(redis.Redis, request) @pytest.fixture() -def r2(request, **kwargs): - return [ - _get_client(redis.Redis, request, **kwargs), - _get_client(redis.Redis, request, **kwargs), - ] +def r2(request): + "A second client for tests that need multiple" + return _get_client(redis.Redis, request) def _gen_cluster_mock_resp(r, response): - mock_connection_pool = Mock() connection = Mock() - response = response connection.read_response.return_value = response - mock_connection_pool.get_connection.return_value = connection - r.connection_pool = mock_connection_pool + r.connection = connection return r |