summaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 0007b84..b0827b3 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,3 +1,5 @@
+import random
+
import pytest
import redis
from mock import Mock
@@ -146,3 +148,22 @@ def mock_cluster_resp_slaves(request, **kwargs):
"slave 19efe5a631f3296fdf21a5441680f893e8cc96ec 0 "
"1447836789290 3 connected']")
return _gen_cluster_mock_resp(r, response)
+
+
+def wait_for_command(client, monitor, command):
+ # issue a command with a key name that's local to this process.
+ # if we find a command with our key before the command we're waiting
+ # for, something went wrong
+ redis_version = REDIS_INFO["version"]
+ if StrictVersion(redis_version) >= StrictVersion('5.0.0'):
+ id_str = str(client.client_id())
+ else:
+ id_str = '%08x' % random.randrange(2**32)
+ key = '__REDIS-PY-%s__' % id_str
+ client.get(key)
+ while True:
+ monitor_response = monitor.next_command()
+ if command in monitor_response['command']:
+ return monitor_response
+ if key in monitor_response['command']:
+ return None