|
| 1 | +# Copyright 2010 New Relic, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import redis |
| 16 | +from testing_support.db_settings import redis_cluster_settings |
| 17 | + |
| 18 | +DB_CLUSTER_SETTINGS = redis_cluster_settings()[0] |
| 19 | + |
| 20 | +# Set socket_timeout to 5s for fast fail, otherwise the default is to wait forever. |
| 21 | +client = redis.RedisCluster(host=DB_CLUSTER_SETTINGS["host"], port=DB_CLUSTER_SETTINGS["port"], socket_timeout=5) |
| 22 | + |
| 23 | +IGNORED_METHODS = { |
| 24 | + "MODULE_CALLBACKS", |
| 25 | + "MODULE_VERSION", |
| 26 | + "NAME", |
| 27 | + "add_edge", |
| 28 | + "add_node", |
| 29 | + "append_bucket_size", |
| 30 | + "append_capacity", |
| 31 | + "append_error", |
| 32 | + "append_expansion", |
| 33 | + "append_items_and_increments", |
| 34 | + "append_items", |
| 35 | + "append_max_iterations", |
| 36 | + "append_no_create", |
| 37 | + "append_no_scale", |
| 38 | + "append_values_and_weights", |
| 39 | + "append_weights", |
| 40 | + "batch_indexer", |
| 41 | + "BatchIndexer", |
| 42 | + "bulk", |
| 43 | + "call_procedure", |
| 44 | + "client_tracking_off", |
| 45 | + "client_tracking_on", |
| 46 | + "client", |
| 47 | + "close", |
| 48 | + "commandmixin", |
| 49 | + "connection_pool", |
| 50 | + "connection", |
| 51 | + "debug_segfault", |
| 52 | + "edges", |
| 53 | + "execute_command", |
| 54 | + "flush", |
| 55 | + "from_url", |
| 56 | + "get_connection_kwargs", |
| 57 | + "get_encoder", |
| 58 | + "get_label", |
| 59 | + "get_params_args", |
| 60 | + "get_property", |
| 61 | + "get_relation", |
| 62 | + "get_retry", |
| 63 | + "hscan_iter", |
| 64 | + "index_name", |
| 65 | + "labels", |
| 66 | + "list_keys", |
| 67 | + "load_document", |
| 68 | + "load_external_module", |
| 69 | + "lock", |
| 70 | + "name", |
| 71 | + "nodes", |
| 72 | + "parse_response", |
| 73 | + "pipeline", |
| 74 | + "property_keys", |
| 75 | + "register_script", |
| 76 | + "relationship_types", |
| 77 | + "response_callbacks", |
| 78 | + "RESPONSE_CALLBACKS", |
| 79 | + "sentinel", |
| 80 | + "set_file", |
| 81 | + "set_path", |
| 82 | + "set_response_callback", |
| 83 | + "set_retry", |
| 84 | + "transaction", |
| 85 | + "version", |
| 86 | + "ALL_NODES", |
| 87 | + "CLUSTER_COMMANDS_RESPONSE_CALLBACKS", |
| 88 | + "COMMAND_FLAGS", |
| 89 | + "DEFAULT_NODE", |
| 90 | + "ERRORS_ALLOW_RETRY", |
| 91 | + "NODE_FLAGS", |
| 92 | + "PRIMARIES", |
| 93 | + "RANDOM", |
| 94 | + "REPLICAS", |
| 95 | + "RESULT_CALLBACKS", |
| 96 | + "RedisClusterRequestTTL", |
| 97 | + "SEARCH_COMMANDS", |
| 98 | + "client_no_touch", |
| 99 | + "cluster_addslotsrange", |
| 100 | + "cluster_bumpepoch", |
| 101 | + "cluster_delslotsrange", |
| 102 | + "cluster_error_retry_attempts", |
| 103 | + "cluster_flushslots", |
| 104 | + "cluster_links", |
| 105 | + "cluster_myid", |
| 106 | + "cluster_myshardid", |
| 107 | + "cluster_replicas", |
| 108 | + "cluster_response_callbacks", |
| 109 | + "cluster_setslot_stable", |
| 110 | + "cluster_shards", |
| 111 | + "command_flags", |
| 112 | + "commands_parser", |
| 113 | + "determine_slot", |
| 114 | + "disconnect_connection_pools", |
| 115 | + "encoder", |
| 116 | + "get_default_node", |
| 117 | + "get_node", |
| 118 | + "get_node_from_key", |
| 119 | + "get_nodes", |
| 120 | + "get_primaries", |
| 121 | + "get_random_node", |
| 122 | + "get_redis_connection", |
| 123 | + "get_replicas", |
| 124 | + "keyslot", |
| 125 | + "mget_nonatomic", |
| 126 | + "monitor", |
| 127 | + "mset_nonatomic", |
| 128 | + "node_flags", |
| 129 | + "nodes_manager", |
| 130 | + "on_connect", |
| 131 | + "pubsub", |
| 132 | + "read_from_replicas", |
| 133 | + "reinitialize_counter", |
| 134 | + "reinitialize_steps", |
| 135 | + "replace_default_node", |
| 136 | + "result_callbacks", |
| 137 | + "set_default_node", |
| 138 | + "user_on_connect_func", |
| 139 | +} |
| 140 | + |
| 141 | +REDIS_MODULES = { |
| 142 | + "bf", |
| 143 | + "cf", |
| 144 | + "cms", |
| 145 | + "ft", |
| 146 | + "graph", |
| 147 | + "json", |
| 148 | + "tdigest", |
| 149 | + "topk", |
| 150 | + "ts", |
| 151 | +} |
| 152 | + |
| 153 | +IGNORED_METHODS |= REDIS_MODULES |
| 154 | + |
| 155 | + |
| 156 | +def test_uninstrumented_methods(): |
| 157 | + methods = {m for m in dir(client) if not m[0] == "_"} |
| 158 | + is_wrapped = lambda m: hasattr(getattr(client, m), "__wrapped__") |
| 159 | + uninstrumented = {m for m in methods - IGNORED_METHODS if not is_wrapped(m)} |
| 160 | + |
| 161 | + for module in REDIS_MODULES: |
| 162 | + if hasattr(client, module): |
| 163 | + module_client = getattr(client, module)() |
| 164 | + module_methods = {m for m in dir(module_client) if not m[0] == "_"} |
| 165 | + is_wrapped = lambda m: hasattr(getattr(module_client, m), "__wrapped__") |
| 166 | + uninstrumented |= {m for m in module_methods - IGNORED_METHODS if not is_wrapped(m)} |
| 167 | + |
| 168 | + assert not uninstrumented, "Uninstrumented methods: %s" % sorted(uninstrumented) |
0 commit comments