diff options
author | Kristján Valur Jónsson <sweskman@gmail.com> | 2022-09-28 13:21:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 16:21:19 +0300 |
commit | 6b3e0b491c4a348ca2e7a332e6f3b23a5da3c461 (patch) | |
tree | ae238a90ce3d724693c3ab4331f5ea1747871051 /tests/test_asyncio/test_cluster.py | |
parent | 7c6a8128660d713f11d34ed4b5652ccbd9548e52 (diff) | |
download | redis-py-6b3e0b491c4a348ca2e7a332e6f3b23a5da3c461.tar.gz |
Dev/no lock (#2308)
* Remove async lock in asyncio.Connection.read_response
* Skip concurrent-commands test on non-pooled connections
Diffstat (limited to 'tests/test_asyncio/test_cluster.py')
-rw-r--r-- | tests/test_asyncio/test_cluster.py | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index e299395..88cfb1f 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -120,7 +120,7 @@ async def get_mocked_redis_client(*args, **kwargs) -> RedisCluster: def mock_node_resp(node: ClusterNode, response: Any) -> ClusterNode: connection = mock.AsyncMock() connection.is_connected = True - connection.read_response_without_lock.return_value = response + connection.read_response.return_value = response while node._free: node._free.pop() node._free.append(connection) @@ -130,7 +130,7 @@ def mock_node_resp(node: ClusterNode, response: Any) -> ClusterNode: def mock_node_resp_exc(node: ClusterNode, exc: Exception) -> ClusterNode: connection = mock.AsyncMock() connection.is_connected = True - connection.read_response_without_lock.side_effect = exc + connection.read_response.side_effect = exc while node._free: node._free.pop() node._free.append(connection) @@ -275,16 +275,12 @@ class TestRedisClusterObj: for node in rc.get_nodes(): assert node.max_connections == 10 - with mock.patch.object( - Connection, "read_response_without_lock" - ) as read_response_without_lock: + with mock.patch.object(Connection, "read_response") as read_response: - async def read_response_without_lock_mocked( - *args: Any, **kwargs: Any - ) -> None: + async def read_response_mocked(*args: Any, **kwargs: Any) -> None: await asyncio.sleep(10) - read_response_without_lock.side_effect = read_response_without_lock_mocked + read_response.side_effect = read_response_mocked with pytest.raises(MaxConnectionsError): await asyncio.gather( @@ -316,10 +312,10 @@ class TestRedisClusterObj: assert await r.ping(target_nodes=RedisCluster.PRIMARIES) is True for primary in primaries: conn = primary._free.pop() - assert conn.read_response_without_lock.called is True + assert conn.read_response.called is True for replica in replicas: conn = replica._free.pop() - assert conn.read_response_without_lock.called is not True + assert conn.read_response.called is not True async def test_execute_command_node_flag_replicas(self, r: RedisCluster) -> None: """ @@ -333,10 +329,10 @@ class TestRedisClusterObj: assert await r.ping(target_nodes=RedisCluster.REPLICAS) is True for replica in replicas: conn = replica._free.pop() - assert conn.read_response_without_lock.called is True + assert conn.read_response.called is True for primary in primaries: conn = primary._free.pop() - assert conn.read_response_without_lock.called is not True + assert conn.read_response.called is not True await r.close() @@ -348,7 +344,7 @@ class TestRedisClusterObj: assert await r.ping(target_nodes=RedisCluster.ALL_NODES) is True for node in r.get_nodes(): conn = node._free.pop() - assert conn.read_response_without_lock.called is True + assert conn.read_response.called is True async def test_execute_command_node_flag_random(self, r: RedisCluster) -> None: """ @@ -359,7 +355,7 @@ class TestRedisClusterObj: called_count = 0 for node in r.get_nodes(): conn = node._free.pop() - if conn.read_response_without_lock.called is True: + if conn.read_response.called is True: called_count += 1 assert called_count == 1 @@ -372,7 +368,7 @@ class TestRedisClusterObj: mock_node_resp(def_node, "PONG") assert await r.ping() is True conn = def_node._free.pop() - assert conn.read_response_without_lock.called + assert conn.read_response.called async def test_ask_redirection(self, r: RedisCluster) -> None: """ @@ -516,7 +512,7 @@ class TestRedisClusterObj: with mock.patch.multiple( Connection, send_command=mock.DEFAULT, - read_response_without_lock=mock.DEFAULT, + read_response=mock.DEFAULT, _connect=mock.DEFAULT, can_read=mock.DEFAULT, on_connect=mock.DEFAULT, @@ -548,7 +544,7 @@ class TestRedisClusterObj: # so we'll mock some of the Connection's functions to allow it execute_command.side_effect = execute_command_mock_first mocks["send_command"].return_value = True - mocks["read_response_without_lock"].return_value = "OK" + mocks["read_response"].return_value = "OK" mocks["_connect"].return_value = True mocks["can_read"].return_value = False mocks["on_connect"].return_value = True @@ -857,8 +853,8 @@ class TestClusterRedisCommands: node0 = r.get_node(default_host, 7000) node1 = r.get_node(default_host, 7001) assert await r.cluster_delslots(0, 8192) == [True, True] - assert node0._free.pop().read_response_without_lock.called - assert node1._free.pop().read_response_without_lock.called + assert node0._free.pop().read_response.called + assert node1._free.pop().read_response.called await r.close() @@ -1027,7 +1023,7 @@ class TestClusterRedisCommands: node = r.nodes_manager.get_node_from_slot(12182) mock_node_resp(node, "OK") assert await r.cluster_setslot_stable(12182) is True - assert node._free.pop().read_response_without_lock.called + assert node._free.pop().read_response.called @skip_if_redis_enterprise() async def test_cluster_replicas(self, r: RedisCluster) -> None: @@ -1069,7 +1065,7 @@ class TestClusterRedisCommands: for res in all_replicas_results.values(): assert res is True for replica in r.get_replicas(): - assert replica._free.pop().read_response_without_lock.called + assert replica._free.pop().read_response.called await r.close() @@ -1082,7 +1078,7 @@ class TestClusterRedisCommands: for res in all_replicas_results.values(): assert res is True for replica in r.get_replicas(): - assert replica._free.pop().read_response_without_lock.called + assert replica._free.pop().read_response.called await r.close() @@ -2441,8 +2437,8 @@ class TestClusterPipeline: mock_node_resp_exc(first_node, AskError(ask_msg)) mock_node_resp(ask_node, "MOCK_OK") res = await pipe.get(key).execute() - assert first_node._free.pop().read_response_without_lock.await_count - assert ask_node._free.pop().read_response_without_lock.await_count + assert first_node._free.pop().read_response.await_count + assert ask_node._free.pop().read_response.await_count assert res == ["MOCK_OK"] async def test_moved_redirection_on_slave_with_default( @@ -2497,7 +2493,7 @@ class TestClusterPipeline: executed_on_replica = False for node in slot_nodes: if node.server_type == REPLICA: - if node._free.pop().read_response_without_lock.await_count: + if node._free.pop().read_response.await_count: executed_on_replica = True break assert executed_on_replica |