If I can't connect to one of the nodes, everything should still work. But if I can't connect to any of the nodes, exception should be thrown.
(self)
| 3085 | |
| 3086 | @pytest.mark.fixed_client |
| 3087 | def test_init_with_down_node(self): |
| 3088 | """ |
| 3089 | If I can't connect to one of the nodes, everything should still work. |
| 3090 | But if I can't connect to any of the nodes, exception should be thrown. |
| 3091 | """ |
| 3092 | with patch.object(NodesManager, "create_redis_node") as create_redis_node: |
| 3093 | |
| 3094 | def create_mocked_redis_node(host, port, **kwargs): |
| 3095 | if port == 7000: |
| 3096 | raise ConnectionError("mock connection error for 7000") |
| 3097 | |
| 3098 | r_node = Redis(host=host, port=port, decode_responses=True) |
| 3099 | |
| 3100 | def execute_command(*args, **kwargs): |
| 3101 | if args[0] == "CLUSTER SLOTS": |
| 3102 | return [ |
| 3103 | [0, 8191, ["127.0.0.1", 7001, "node_1"]], |
| 3104 | [8192, 16383, ["127.0.0.1", 7002, "node_2"]], |
| 3105 | ] |
| 3106 | elif args[0] == "INFO": |
| 3107 | return {"cluster_enabled": True} |
| 3108 | elif args[1] == "cluster-require-full-coverage": |
| 3109 | return {"cluster-require-full-coverage": "yes"} |
| 3110 | |
| 3111 | r_node.execute_command = execute_command |
| 3112 | |
| 3113 | return r_node |
| 3114 | |
| 3115 | create_redis_node.side_effect = create_mocked_redis_node |
| 3116 | |
| 3117 | node_1 = ClusterNode("127.0.0.1", 7000) |
| 3118 | node_2 = ClusterNode("127.0.0.1", 7001) |
| 3119 | |
| 3120 | # If all startup nodes fail to connect, connection error should be |
| 3121 | # thrown |
| 3122 | with pytest.raises(RedisClusterException) as e: |
| 3123 | RedisCluster(startup_nodes=[node_1]) |
| 3124 | assert "Redis Cluster cannot be connected" in str(e.value) |
| 3125 | |
| 3126 | with patch.object( |
| 3127 | CommandsParser, "initialize", autospec=True |
| 3128 | ) as cmd_parser_initialize: |
| 3129 | |
| 3130 | def cmd_init_mock(self, r): |
| 3131 | self.commands = { |
| 3132 | "get": { |
| 3133 | "name": "get", |
| 3134 | "arity": 2, |
| 3135 | "flags": ["readonly", "fast"], |
| 3136 | "first_key_pos": 1, |
| 3137 | "last_key_pos": 1, |
| 3138 | "step_count": 1, |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | cmd_parser_initialize.side_effect = cmd_init_mock |
| 3143 | # When at least one startup node is reachable, the cluster |
| 3144 | # initialization should succeeds |
nothing calls this directly
no test coverage detected