diff options
author | Ian Bucad <ian.bucad@datadoghq.com> | 2021-08-29 18:40:29 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-29 11:40:29 +0300 |
commit | 41e3f56f65b690ae39ab798a85b42e44ee72a829 (patch) | |
tree | b03d494beb2c69bbb0dc1226c1805601456679c7 /tests | |
parent | 9f82778b78b2e4fd1482255edc91d10c4dda2988 (diff) | |
download | redis-py-41e3f56f65b690ae39ab798a85b42e44ee72a829.tar.gz |
Includes slowlog complexity info if available (#1489)
* Return slowlog complexity info if available
based on https://github.com/andymccurdy/redis-py/pull/622
* Add tests
Copied from https://github.com/andymccurdy/redis-py/pull/622
* address flake E306
* Trigger Build
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_commands.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py index 4b7957c..0e71fcf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -499,6 +499,35 @@ class TestRedisCommands: assert isinstance(slowlog[0]['start_time'], int) assert isinstance(slowlog[0]['duration'], int) + # Mock result if we didn't get slowlog complexity info. + if 'complexity' not in slowlog[0]: + # monkey patch parse_response() + COMPLEXITY_STATEMENT = "Complexity info: N:4712,M:3788" + old_parse_response = r.parse_response + + def parse_response(connection, command_name, **options): + if command_name != 'SLOWLOG GET': + return old_parse_response(connection, + command_name, + **options) + responses = connection.read_response() + for response in responses: + # Complexity info stored as fourth item in list + response.insert(3, COMPLEXITY_STATEMENT) + return r.response_callbacks[command_name](responses, **options) + r.parse_response = parse_response + + # test + slowlog = r.slowlog_get() + assert isinstance(slowlog, list) + commands = [log['command'] for log in slowlog] + assert get_command in commands + idx = commands.index(get_command) + assert slowlog[idx]['complexity'] == COMPLEXITY_STATEMENT + + # tear down monkeypatch + r.parse_response = old_parse_response + def test_slowlog_get_limit(self, r, slowlog): assert r.slowlog_reset() r.get('foo') |